procedure Tf_yrdwfileinfo.FTP_DownloadDir(remote_dir,local_dir:string); //下载整个目录,并遍历所有子目录 使用clftp var i,j,count1:integer; att,ss:string; current_dir,remote_dir2,currfile:string; temp_dir,ftpdir:string; F:textfile; diratt:string; filei:TFtpFileInfo; lst : TStringList; begin ftpdir:=FtpClient1.HostDirName; remote_dir2:=ftpdir+'/'+remote_dir; FtpClient1.HostDirName :=remote_dir2; //==========刷新目录 ftprefurbish(False ); //========== current_dir:=remote_dir2; //主目录 temp_dir :=remote_dir ; if not DirectoryExists(local_dir) then CreateDir(local_dir); if not directoryexists(local_dir+'\'+temp_dir) then createdir(local_dir+'\'+temp_dir);
lst := TStringList.Create; lst.LoadFromFile(TEMP_FILE_NAME); for i :=2 to lst.Count - 1 do begin diratt:=lst[i]; filei:=GetFileInfo(diratt); if (copy(filei.Attrib ,1,1)<>'d') then begin //if not DirectoryExists(local_dir) then CreateDir(local_dir); //创退本地目录 //==========下载文件 ftpclient1.Pwd ; currfile:=ftpclient1.DirResult ; currfile:=currfile+'/'+filei.FileName ; ftpclient1.HostFileName :=currfile; Ftpclient1.Binary :=true; FtpClient1.TypeSet ; ftpclient1.LocalFileName :=local_dir+'\'+temp_dir+'\'+filei.FileName ; ftpclient1.Get ; Ftpclient1.Binary :=false; FtpClient1.TypeSet ; //========== end else begin if not (filei.Filename ='..') then begin FTP_DownloadDir(filei.FileName,local_dir+'\'+remote_dir); end; end; end; lst.Free ; end; |