//------------------------------------------------------------------------------
procedure TransferFromFtp(
const PathName, WildCard:
string);
//------------------------------------------------------------------------------
// Datei per FTP vom Server übertragen
//------------------------------------------------------------------------------
var
FtpClient : TIdFTP;
FileList : TStringList;
LocalFile :
string;
i : integer;
begin
FtpClient := TIdFTP.Create(
nil);
FileList := TStringList.Create;
try
FtpClient.Host := Config.Server;
FtpClient.Username := Config.User;
FtpClient.Password := Config.Pass;
try
Logg('
Connecting to %s', [Config.Server]);
FtpClient.Connect();
try
FtpClient.List(FileList, PathName+WildCard);
FileList.Clear;
with FtpClient.DirectoryListing
do
for i := 0
to Count -1
do
begin
LocalFile := ExtractFileName(StringReplace(Items[i].FileName, '
/', '
\', [rfReplaceAll]));
FtpClient.Get(Config.InPath+LocalFile, IncludeTrailingPathDelimiter(Config.ImportDir)+LocalFile);
// Nach dem Abholen löschen
FtpClient.Delete(Config.InPath+LocalFile);
Logg('
Transfered %s', [IncludeTrailingPathDelimiter(Config.ImportDir)+LocalFile]);
end;
except
on e :
Exception do Logg('
FTP transfer error: %s', [e.
Message]);
end;
except
on e :
Exception do Logg('
FTP connect error: %s', [e.
Message]);
end;
Logg('
Disconnecting from %s', [Config.Server]);
FtpClient.Disconnect;
finally
FtpClient.Free;
FileList.Free;
end;
end;