整了半天也没有搞出来,搜编了网络也没有找到一个解决方法:
搞到了一段代码,可是存在如下问题:
1.  nmftp1.FTPDirectoryList.name.Count总是为0;
2.  (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') 中的这个‘d’是指什么意思。
没有接触过这方面的东西,任务又紧,来不及细细摸索了,故请兄弟们相助,帮我调试一下这段代码或者有什么别的好办法,请指点一二,分数好说,不够尽管开口,直到破产为止!
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
            
            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);
                
                ex_download(remote_dir+ss+'\',local_dir);
            end;
        end;
           result:=true;
    end
    except
    On E:Exception do begin
        result:=false;
    end;
    end;
end;

解决方案 »

  1.   

    2.  (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D')这里的 D 是文件属性为 目录 (directory)
      

  2.   

    谢谢Demonia兄指教,揭帖的时候就给20分,剩余80分继续求解!
      

  3.   

    procedure GetP_afile;
    var LastDay:string;
        mstr:string;
     begin
         {Find Last files}
            FFtp.FindFiles(FP_afile+'/*.*');
         if FFtp.FindFilesCount>0 then
         begin
              LastDay:=GetFileHead(FFtp.FindFile.FileName);
              FFtp.NextFindFile;
              while not FFtp.FindFilesEOF do
              begin
                   if (LastDay<GetFileHead(FFtp.FindFile.FileName)) or (lastday='') then
                      Lastday:=GetFileHead(FFtp.FindFile.FileName);
                      FFtp.NextFindFile;
              end;
         end else
         begin
              exit;
         end;
         if (trim(LastDay)='.') or (trim(LastDay)='..') then
           exit;
         FFtp.findfiles(FP_afile+'/'+LastDay+'.??');
            {Get Last Files}
              while not FFtp.FindFilesEOF do
         begin
      if (FFtp.findfile.FileName<>'.' ) and (FFtp.findfile.FileName<>'..') then
      begin
               FFtp.GetFile(FP_afile+'/'+FFtp.findfile.FileName,FLP_afile+'\'+FFtp.findfile.FileName);
              end;
              FFtp.NextFindFile;
         end;
      

  4.   

    谢谢asterlx() 了,揭帖给分了
    lxm5717() ,我们下面联系
    [email protected]
      

  5.   

    将上面代码改写了一边,D7的Indy控件,代码如下,以供和我一样的生手免走弯路function TForm1.ex_download(remote_dir, local_dir: string): boolean;
    var
      i,j,FileCount:integer;
      FileFolder,FileName:string;
      current_dir:string;
      Current_folder:string;
      tmp_str,tmp_folder:string;
      tmp_list:TStringList;
    begin
      try
        tmp_list:=TStringList.Create;
        IdFTP1.ChangeDir(remote_dir);
        current_dir:=remote_dir;
        Current_folder:=copy(current_dir,2,length(current_dir));   //文件夹名
        tmp_str:=local_dir+'\'+Current_folder+'\';
        while pos('\',tmp_str)<>0 do             //在当前下载目录下创建同文件夹名
        begin
          tmp_folder:=copy(tmp_str,1,pos('\',tmp_str)-1);
          if trim(tmp_folder)<>'' then
            tmp_list.Add(tmp_folder);
          tmp_str:=copy(tmp_str,pos('\',tmp_str)+1,MaxInt);
        end;
        tmp_str:=tmp_list.Strings[0];
        for j:=1 to tmp_list.Count-1 do     //从1开始丢掉盘符
        begin
          tmp_str:=tmp_str+'\'+tmp_list.Strings[i];
          if not DirectoryExists(tmp_str) then
            CreateDir(tmp_str);
        end;
        tmp_list.Clear;
           
        IdFTP1.List(IdFTP1.ListResult);    FileCount:=IdFTP1.DirectoryListing.Count;    //本目录文件数目    for i:=0 to FileCount-1 do
        begin    //必须
          IdFTP1.ChangeDir(current_dir);
          IdFTP1.List(IdFTP1.ListResult);      FileName:=IdFTP1.DirectoryListing.Items[i].FileName;
          if pos('DIR',IdFTP1.DirectoryListing.Items[i].Text)=0 then    //为文件
          begin
            IdFTP1.Get(FileName,local_dir+'\'+Current_folder+'\'+FileName,true);
          end
          else         //为文件夹
          begin
          if not directoryexists(local_dir+'\'+Current_folder+'\'+FileName) then
            createdir(local_dir+'\'+Current_folder+'\'+FileName);
            //current_dir:= local_dir+'\'+Current_folder+'\'+FileName;
            //递归调用
            ex_download(remote_dir+'\'+FileName+'\',local_dir);
          end;
        end;
        tmp_list.Free;
        result:=true;
      except
        On E:Exception do
        begin
          result:=false;
        end;
      end;
    end;