使用ftp控件下载一个目录.txt

来自「大量Delphi开发资料」· 文本 代码 · 共 51 行

TXT
51
字号
使用FTP控件下载一个目录
DELPHI中的nmftp控件中Download函数只能下载一个文件,没有提供一个下载整个目
录(包含子目录)的函数。
我编写了个实现目录下载功能的方法,需要用到该功能的用户可参考一下。
file://目录下载
function tftp.ex_download(remote_dir,local_dir:string):boolean;
var
 i,j,count1:integer;
 att,ss:string;
 current_dir:string;
 temp_dir:string;
begin
 try begin
 NMFTP1.ChangeDir(remote_dir);
 current_dir:=remote_dir;
 temp_dir:=copy(current_dir,2,length(current_dir));
 if not DirectoryExists(local_dir) then CreateDir(local_dir);
 if not directoryexists(local_dir+temp_dir) then
createdir(local_dir+temp_dir);
 nmftp1.ParseList:=true;
 NMftp1.list;
 count1:=nmftp1.FTPDirectoryList.name.Count;
 for i:=0 to count1-1 do begin
 file://必须
 NMFTP1.ChangeDir(current_dir);
 nmftp1.list;
 ss:=nmftp1.FTPDirectoryList.name.Strings[i];
 att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];
 if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D')
then begin
 if not DirectoryExists(local_dir) then
CreateDir(local_dir);
 NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);
 end
 else begin
 if not directoryexists(local_dir+temp_dir+ss) then
createdir(local_dir+temp_dir+ss);
 file://递归调用
 ex_download(remote_dir+ss+'\',local_dir);
 end;
 end;
 result:=true;
 end
 except
 On E:Exception do begin
 result:=false;
 end;
 end;
end;
相关连接:http://www.delphibbs.com

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?