关于用IDFTP递归下载目录!

msi 2004-04-22 09:32:03
如何用idftp递归下载目录哪?请那位高手给我这多CODE!多谢了!
...全文
288 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
smandhgx 2004-04-23
  • 打赏
  • 举报
回复
我已经在delphi专区发表了一篇文章:ifFTP第归下载、删除,自己看看

{ 下载整个目录,并遍历所有子目录
首先 ChangeDir(Root) 到根目录
然后创建本地目录 + RemoteDir
然后用 list 得到所有目录名
循环判断,进入 RemoteDir 目录内部
如果是目录继续第归。否则 get 该文件到本地目录,当 get 完所有文件后返回上一级目录
用List再取得信息,继续循环
}

procedure FTP_DownloadDir(var idFTP : TIdFtp;RemoteDir,LocalDir : string);
label Files ;
var
i,DirCount : integer;
begin
if not DirectoryExists(LocalDir + RemoteDir) then
ForceDirectories(LocalDir + RemoteDir);
idFTP.ChangeDir(RemoteDir);
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count ;
if DirCount = 0 then
begin
idFTP.ChangeDirUp;
idFTP.List(nil);
end;
for i := 0 to DirCount - 1 do
begin
if DirCount <> idFTP.DirectoryListing.Count then
begin
repeat
idFTP.ChangeDirUp;
idFTP.List(nil);
until DirCount = idFTP.DirectoryListing.Count ;
end;
if idFTP.DirectoryListing[i].ItemType = ditDirectory then
FTP_DownloadDir(idFTP,idFTP.DirectoryListing[i].FileName,LocalDir + RemoteDir + '\')
else begin
idFTP.Get(idFTP.DirectoryListing[i].FileName,LocalDir + RemoteDir + '\' +
idFTP.DirectoryListing[i].FileName,true);
//Form1.lb_num.Caption := IntToStr(StrToInt(Form1.lb_num.Caption) + 1);
//Form1.lb_num.Update;
if i = DirCount - 1 then
begin
idFTP.ChangeDirUp;
idFTP.List(nil);
end;
end;
end;
end;

procedure TForm1.Btt_DownLoadDirClick(Sender: TObject);
begin
IdFTP1.Connect(true,-1);
if IdFTP1.Connected then
begin
IdFTP1.ChangeDir('bigimage');
FTP_DownloadDir(IdFTP1,'1002.1002.1002','g:\ftpdir\');
end;
IdFTP1.Disconnect ;
end;
eboywy 2004-04-23
  • 打赏
  • 举报
回复
楼上的老兄高人啊。技术腿脚都是一流!佩服!
msi 2004-04-23
  • 打赏
  • 举报
回复
我先谢谢大家了!
aiirii 2004-04-22
  • 打赏
  • 举报
回复
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;

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧