Loop through all files on ftp

Giganews Newsgroups
Subject: Loop through all files on ftp
Posted by:  Cyclone (klo…@kloon.za.net)
Date: Mon, 4 Jun 2007

Hey i tried the folowing code to loop through all the files on a ftp server
but to no avail does it do that.

procedure TForm1.ProcessCurrentDirectory;
    var
        I: Integer;
        Directories: TStringList;
        Item: TIdFTPListItem;
        CurrentDir: String;
    begin
        ftp.List(nil,'',false);
        Directories := TStringList.Create;
        try
            for I := 0 to FTP.DirectoryListing.Count-1 do
            begin
                Item := FTP.DirectoryListing[I];
                case Item.ItemType of
                    ditDirectory:
                        Directories.Add(Item.FileName);
                    ditFile, ditSymbolicLink:
                        //ListBox1.Items.Add(Item.FileName);
                end;
            Listbox1.Items.Add(Item.FileName);
            end;
            for I := 0 to Directories.Count-1 do
            begin
                CurrentDir := FTP.RetrieveCurrentDir;
                FTP.ChangeDir(CurrentDir + Directories[I]);
                ProcessCurrentDirectory;
            end;
        finally
            Directories.Free;
        end;
    end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FTP.Connect;
  try
    ProcessCurrentDirectory;
  finally
    FTP.Disconnect;
  end;
end;

Replies