// === FTP Download Folder =====================================================
// = Uses: IdFTPList
procedure TForm1.DownloadFolder(AFTP: TIdFtp; ARemotePath, ALocalPath:
string);
var
I: Integer;
begin
ALocalPath := IncludeTrailingPathDelimiter(ALocalPath);
ForceDirectories(ALocalPath);
if ARemotePath[Length(ARemotePath)] <> '
/'
then ARemotePath := ARemotePath +'
/';
try
AFTP.List;
except
on E:
Exception do MessageDlg(E.
Message, mtError, [mbOk], 0);
end;
for I := 0
to AFTP.DirectoryListing.Count -1
do
begin
// = File Handling
if AFTP.DirectoryListing[i].ItemType = ditFile
then
begin
if Fileexists(ALocalPath +AFTP.DirectoryListing[i].FileName)
then DeleteFile(ALocalPath +AFTP.DirectoryListing[i].FileName);
AFTP.Get(AFTP.DirectoryListing[i].FileName, ALocalPath +AFTP.DirectoryListing[i].FileName);
end;
// = Folder Handling
if AFTP.DirectoryListing[i].ItemType = ditDirectory
then
begin
AFTP.ChangeDir(AFTP.DirectoryListing[i].FileName);
DownloadFolder(AFTP, AFTP.DirectoryListing[i].FileName, ALocalPath + AFTP.DirectoryListing[i].FileName);
end;
end;
end;
// === Button "Download" =======================================================
procedure TForm1.Button1Click(Sender: TObject);
// = Uses: IdFTPCommon
var
FTPServer : TIdFTP;
begin
// = Create FTP-Instance
FTPServer := TIdFTP.Create(
nil);
FTPServer.Passive := true;
FTPServer.TransferType := ftBinary;
FTPServer.Username := '
test';
FTPServer.Password := '
test';
FTPServer.Host := '
FTP-SERVER';
FTPServer.Port := 21;
try
FTPServer.Connect;
except
on E:
Exception do
begin
MessageDlg(E.
Message, mtError, [mbOk], 0);
FTPServer.Disconnect;
FTPServer.Quit;
exit;
end;
end;
// = Download Folder
ForceDirectories(ExtractFilePath(ParamStr(0)) +'
\folder');
FTPServer.ChangeDir('
folder');
DownloadFolder(FTPServer, '
folder', ExtractFilePath(ParamStr(0))+'
\folder');
// = Disconnect and Free FTP-Instance
FTPServer.Disconnect;
FTPServer.Quit;
end;