Get the complete FTP directory tree.

The sample connects to a FTP server and gets the complete FTP directory tree recursively.
 
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear();
 
  clFtp1.Server := edtHost.Text;
  clFtp1.Port := StrToInt(edtPort.Text);
  clFtp1.UserName := edtUser.Text;
  clFtp1.Password := edtPassword.Text;
  clFtp1.Open();
  try
    FLevel := '';
    GetRecursiveList(edtRoot.Text, '');
  finally
    clFtp1.Close();
  end;
  ShowMessage('Done');
end;
 
procedure TForm1.GetRecursiveList(const ADirName, ALevel: string);
var
  old: string;
begin
  old := FLevel;
  try
    FLevel := FLevel + ALevel;
    clFtp1.ChangeCurrentDir(ADirName);
    clFtp1.DirectoryListing();
    clFtp1.ChangeToParentDir();
  finally
    FLevel := old;
  end;
end;
 
procedure TForm1.clFtp1DirectoryListing(Sender: TObject; AFileInfo: TclFtpFileInfo; 
const Source: string);
begin
  Memo1.Lines.Add(FLevel + AFileInfo.FileName);
  if (AFileInfo.IsDirectory) then
  begin
    GetRecursiveList(AFileInfo.FileName, #9);
  end;
end;

Add Feedback