再给你一个实现目录下载的例子: 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;
TO :cg1120(代码最优化)兄 你好, 你给的有关API的资料很全,不过有可以参考的代码就更好了, 你给的那段下载整个目录的代码是用nmftp组件写的呀,我的意思是最好不用 这个组件,因为这个组件好象运行起来很不稳定 另外,衷心感谢
Indy也不错,我认为如果有控件就可以用控件,如果不满意可以改代码。
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;
你好,
你给的有关API的资料很全,不过有可以参考的代码就更好了,
你给的那段下载整个目录的代码是用nmftp组件写的呀,我的意思是最好不用
这个组件,因为这个组件好象运行起来很不稳定
另外,衷心感谢