Board index » delphi » FTP directory listing

FTP directory listing

You should of course insert your own parameters here:
Quote
>   with IdFTP1 do
>   begin
>     host:= 'domain.com';
>     passive:= true;
>     password:= 'password';
>     transfertype:= ftASCII;
>     username:= 'admin';
>   end;

 

Re:FTP directory listing


Hi

I have for a long time needed a simple application, which could log into
my website and give me a list of all files and the total size of them
(sub-dirs included). Well, here it is. Just save as a DPR file and
compile it. It creates a nice CSV file, which can then be opened in
Excel for further sorting, inspection etc.

If someone finds it usefull, I will try to upload it at codecentral.

Regards
Uffe Kousgaard

program FTP_listing;
{$APPTYPE CONSOLE}
uses
  classes,SysUtils,IdFTP,IdFTPlist,IdFTPCommon;

var
  LS: TStringList;
  IdFTP1: TIdFTP;
  f: textfile;

function sizefunc: integer;
Var
  i,Fsize: integer;
begin
  result:= 0;
  try
    IdFTP1.List(LS);
    for i:= 0 to LS.Count-1 do
    begin
      Fsize:= IdFTP1.DirectoryListing.Items[i].Size;
      result:= result+Fsize;
      if Fsize<>0 then
      begin
        write('.');

writeln(f,IdFTP1.RetrieveCurrentDir+ListSeparator+IdFTP1.DirectoryListin
g.Items[i].filename+ListSeparator+inttostr(Fsize));
      end;
    end;
    for i:= 0 to LS.Count-1 do
    begin
      if IdFTP1.DirectoryListing.Items[i].ItemType = ditDirectory then
      begin
        IdFTP1.ChangeDir(IdFTP1.DirectoryListing.Items[i].FileName);
        result:= result+sizefunc;
        IdFTP1.ChangeDirUp;
        IdFTP1.List(LS);
      end;
    end;
  finally
  end;
end;

begin
  LS:= TStringList.Create;
  IdFTP1:= TIdFTP.Create(nil);
  with IdFTP1 do
  begin
    host:= 'domain.com';
    passive:= true;
    password:= 'password';
    transfertype:= ftASCII;
    username:= 'admin';
  end;

  try
    IdFTP1.Connect;
  finally
    if IdFTP1.Connected then
    begin
      IdFTP1.ChangeDir('.\');
      assignfile(f,'ftp_dir.csv');
      rewrite(f);
      write('Working');
      writeln(f,inttostr(sizefunc)+' bytes');
      writeln;
      writeln('Done');
      closefile(f);
    end;
  end;

  LS.Free;
  idFTP1.Disconnect;
  IdFTP1.Free;
end.

Other Threads