I Need to download files from a FTP-Server with Lazarus. I have already a function for connecting to the Server but no idea how I can download files from it.
我需要从带有Lazarus的FTP服务器下载文件。我已经有一个连接到服务器的功能,但不知道如何从中下载文件。
I hope someone can give me a Code example on that.
我希望有人可以给我一个代码示例。
Connecting to FTP-Server:
连接到FTP服务器:
function connect(Host, Username, Password : string) : boolean;
var
FTP: TFTPSend;
begin
FTP := TFTPSend.Create;
FTP.TargetHost := Host;
FTP.TargetPort := Port;
FTP.AutoTLS := true;
FTP.Username := username;
FTP.Password:= Password;
FTP.Login;
1 个解决方案
#1
4
You can download a file thru TFTPSend.RetrieveFile function
您可以通过TFTPSend.RetrieveFile函数下载文件
function RetrieveFile(const FileName: string; Restore: Boolean): Boolean; virtual;
function RetrieveFile(const FileName:string; Restore:Boolean):Boolean;虚拟;
var
FTP: TFTPSend;
begin
FTP := TFTPSend.Create;
try
....
FTP.DirectFileName := LocalPath;
FTP.DirectFile := True;
FTP.RetrieveFile(RemotePath, True);
....
finally
FTP.Free;
end;
end;
Also you can use this function FtpGetFile
您也可以使用此功能FtpGetFile
function FtpGetFile(const IP, Port, FileName, LocalFile, User, Pass: string): Boolean;
function FtpGetFile(const IP,Port,FileName,LocalFile,User,Pass:string):Boolean;
Update To download all files in given directory you need to perform loop as below:
更新要下载给定目录中的所有文件,您需要执行如下循环:
FTP.DirectFile:=True;
if FTP.List('', False) then
for I := 0 to FTP.FtpList.Count-1 do begin
FTP.DirectFileName := FTP.FtpList[I].FileName;
FTP.RetrieveFile(FTP.FtpList[I].FileName, True);
end;
Check TFTPSend.List for more information.
检查TFTPSend.List以获取更多信息。
#1
4
You can download a file thru TFTPSend.RetrieveFile function
您可以通过TFTPSend.RetrieveFile函数下载文件
function RetrieveFile(const FileName: string; Restore: Boolean): Boolean; virtual;
function RetrieveFile(const FileName:string; Restore:Boolean):Boolean;虚拟;
var
FTP: TFTPSend;
begin
FTP := TFTPSend.Create;
try
....
FTP.DirectFileName := LocalPath;
FTP.DirectFile := True;
FTP.RetrieveFile(RemotePath, True);
....
finally
FTP.Free;
end;
end;
Also you can use this function FtpGetFile
您也可以使用此功能FtpGetFile
function FtpGetFile(const IP, Port, FileName, LocalFile, User, Pass: string): Boolean;
function FtpGetFile(const IP,Port,FileName,LocalFile,User,Pass:string):Boolean;
Update To download all files in given directory you need to perform loop as below:
更新要下载给定目录中的所有文件,您需要执行如下循环:
FTP.DirectFile:=True;
if FTP.List('', False) then
for I := 0 to FTP.FtpList.Count-1 do begin
FTP.DirectFileName := FTP.FtpList[I].FileName;
FTP.RetrieveFile(FTP.FtpList[I].FileName, True);
end;
Check TFTPSend.List for more information.
检查TFTPSend.List以获取更多信息。