最近用Indy的FTPServer编写FTP服务器,发现不能正常LIST文件列表,客户端用CuteFtp,而用一使用API写的客户端正常,上传文件的话,文件存放的地址也正确。????????不懂,难道是OnListDirectory的问题????各位老大给点建议,或给点源代码参考一下。

解决方案 »

  1.   

    procedure TdmVFTPServer.AddFTPFileList(ADirectoryListing: TIdFTPListItems;
      AFolder: string);
    var
      w32fd: TWin32FindData;
      h: THandle;
      lTime: TFileTime;
      sTime: TSystemTime;
    begin
      if not DirectoryExists(AFolder) then Exit;
      if AFolder[Length(AFolder)] = '\'
         then AFolder := AFolder + '*.*'
         else AFolder := AFolder + '\*.*';
      h := Windows.FindFirstFile(PChar(AFolder), w32fd);
      while h <> INVALID_HANDLE_VALUE do
        begin
          with ADirectoryListing.Add, w32fd do
            begin
              FileName := ExtractFileName(cFileName);
              if (dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0
                 then ItemType := ditFile
                 else ItemType := ditDirectory;
              Size := nFileSizeHigh * MAXDWORD + nFileSizeLow;
              FileTimeToLocalFileTime(ftCreationTime, lTime);
              if FileTimeToSystemTime(lTime, sTime)
                 then ModifiedDate := EncodeDate(sTime.wYear, sTime.wMonth, sTime.wDay) + EncodeTime(sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliSeconds)
                 else ModifiedDate := Now;
              GroupName := vft_FTP;
              OwnerName := vft_FTP;
              UserPermissions := 'rw-';
              GroupPermissions := 'rw-';
              OwnerPermissions := 'rw-';
             end;
          if not Windows.FindNextFile(h, w32fd) then Break;
        end;
      Windows.FindClose(h);
    end;在List事件处理:AddFTPFileList(ADirectoryListing, ConvertFTPPathToLocalPath(APath, false));上面的只是方法,自己分析一下吧http://lysoft.7u7.net
      

  2.   

    TO: ly_liuyang(Liu Yang)
    能否给一下ConvertFTPPathToLocalPath(APath, false)的代码?设置Homedir和CurrentDir按FTP目录结构还是按WINDOWS目录结构方式。先谢了!!!!