我需要在BCB6程序中用到一次很简单的FTP文件检索,用的是NMFTP控件,在使用中我发现用“NMFTP1->FTPDirectoryList->ModifDate->Strings[i]”会根据当前年份不同返回的是如下两种不同的日期字符串:A:如果文件日期与当前年份相同则只返回"Jul  6 11:38 "这种格式不包含年份的字符串值;
B:如果文件日期与当前年份不同则返回的是"Jul 31  2003"这种格式不包含时间的字符串;而我需要的是一个月日年时分秒完整 TDateTime 型值,如(2004-6-28 22.09.33)这种!C++Builder 版人气实在不旺,所以过来求助于大家帮忙,希望大家多多捧场捧场!

解决方案 »

  1.   

    请不要用NM组件,已淘汰兼无法修改内部代码
    Indy的IdFTP才有定制性你需要定制List方法为List -T参数才能获得完整时间修改IdFTP.pas的
    Dest := TStringStream.Create(''); try   {Do not translate}
        if ADetails then begin
          InternalGet('LIST -T', LDest);  {Do not translate}
        end else begin
          InternalGet('NLST', LDest);  {Do not trnalstate}
        end;
      

  2.   

    呵呵
    List是FTP的命令
    DOS下那个FTP.exe不能支持的最好看RFC959协议,就有很清楚的FTP命令
    一般有以下那么多:
     USER    PORT    RETR    ALLO    DELE    SITE    XMKD    CDUP    FEAT
     PASS    PASV    STOR    REST    CWD     STAT    RMD     XCUP    OPTS
     ACCT    TYPE    APPE    RNFR    XCWD    HELP    XRMD    STOU    AUTH
     REIN    STRU    SMNT    RNTO    LIST    NOOP    PWD     SIZE    PBSZ
     QUIT    MODE    SYST    ABOR    NLST    MKD     XPWD    MDTM    PROT还有一样要说就是目前没有那个FTP组件能支持带参数的List命令,所以必须自己修改IdFTP的源代码才能实现的你需要定制List方法为List -T参数才能获得完整时间
      

  3.   

    十分感谢 ly_liuyang 的热心帮助,我先试试!
      

  4.   

    Liu Yang:我用的是 C++Builder6 SP4 ,将原 NMFTP 换成了 IdFTP,但在 IdFTP.pas 中没有找到与你写出的一样的代码段,我改的是这里:procedure TIdFTP.List(ADest: TStrings; const ASpecifier: string = '';
      const ADetails: boolean = true);
    var
      LDest: TStringStream;
    begin
      LDest := TStringStream.Create('');
      try
        if ADetails then
        begin
          InternalGet(trim('list -T ' + ASpecifier), LDest);
        end
        else
        begin
          InternalGet(trim('nlst ' + ASpecifier), LDest);
        end;
        ADest.Text := LDest.DataString;
      finally LDest.Free;
      end;
    end;但改完了,Build All Project ,运行的结果与原来一模一样,是怎么回事啊?
      

  5.   

    另外,我在官方网站下了一个 indy9 的压缩包,但这不知道东西该怎么安装啊? 请指教!
      

  6.   

    同一般的组件一样的安装方法
    但首先要去除Install Package的Indy选项,才能继续的具体看相关书本了==
    就是上边那段
    但可以不做改变的不改变的话,调用改为List(ADest,'-T');效果一样我用的Indy是自己改的版本故和实际的有所出入==
    还有关键的是FTP服务器要支持Lits -T方法,目前有Serv-U,RDFTPD等
    但IIS之类的是不支持的
      

  7.   

    这回可以了,谢谢 Liu Yang !不过 IdFTP1->List(Memo1->Lines, "-T test.rar", true); 得到的是如下的字符串:-rw-rw-rw-  1 user   group   6303198  Jun 21 09:02:39 2004  test.rar
    ---------------------------------------------------------------------
    而不像“NMFTP1->FTPDirectoryList->ModifDate->Strings[i]”可以取到“ModifDate”(虽然不完整),这样的一个长字符串要如何过滤出日期呀?好头疼,不会要写个函数根据空格来取日期部分的字符串吧??再说即使取出“Jun 21 09:02:39 2004”日期串也不能直接转换为 TDateTime 型啊?StrToDateTime("Jun 21 09:02:39 2004") ; //根本就不认这种字符串大侠,帮人帮到底吧! 解决马上结贴!!!
      

  8.   

    IdFTP的DirectoryListing.Parse方法可以解释目录列表的
    看IDFTP的Help了IdFTPList.pas就是解释列表的,但有点Bug了,自己修正去了
      

  9.   

    Help 我翻了好几遍就是没找到与 Directory 相关的方法,DirectoryListing.Parse 方法 Indy 9 才有吧,BCB6 自带的 8.0.25 里面没有啊!昨天装 Indy9 出错了,今天再试试!
      

  10.   

    我安装 Indy9 时总出现如下错误:
    "无法定位程序输入点 @Idresourcestrings@_RSBindingAny 于动态链接库 Indy60.bpl 上。"我下载了两个 Indy9 的压缩包,indy9.zip、Indy_9_00_14_src.zip ,
    indy9.zip 中的文件日期比另一个新一些,indy9.zip 直接解开后里面有 243 个源文件和 3 个文件夹"AZ Demos、Boxster、SyncObjs",直接点击"Fullc6.bat"链接源文件后在其上级目录中会生成一个"C6"目录,之后在 C++Builder6 环境中 Romove 原有 Indy 组件后 Add Packages ,选择"C6"目录中的"dclIndy60.bpl",确定后就出现了上面的错误!我错在哪里了呢?
      

  11.   

    啊,真不容易,Indy9 这回安装成功了!
      

  12.   

    呵呵,搞个东西不是那么容易的还要记得Indy的IdFTPList.pas文件有点Bug的,不能支持部分FTP服务器返回的格式
    如果不好彩的话,你就要修改代码了
      

  13.   

    郁闷啊! 在 Indy9 中也没有找到 DirectoryListing 方法啊?到底是怎么用的啊?大侠,贴一点代码好不好?? 这只要这一小部分!!!Liu Yang 说Indy的IdFTPList.pas文件有点Bug,能不能将你改过的发给我一份啊?我真的快不行了,这么一个破问题弄得我折腾了两天,再这样有人要跳楼了!
      

  14.   

    为了 Indy9,我重装了两次 BCB6 ,我容易吗?
      

  15.   

    Indy9的Help文件才有的TIdFTP.DirectoryListing
    TIdFTP, See Also
    Container for a structured file and directory listing.
    property DirectoryListing: TIdFTPListItems;
    Description
    DirectoryListing is a read-only TIdFTPList property that represents the container and parser for TIdFTPListItem instances created from the result values for the List or Status methods. DirectoryListing is always cleared prior to adding the values returned by List or Status.
    DirectoryListing provides a structured means of accessing data about files and directories returned from the FTP LIST, NLST, or STAT commands. DirectoryListing can also be used to populate GUI controls that display the results of the FTP operation, like TTreeView.DirectoryListing can be used with the OnParseCustomListFormat event handler to allow parsing of FTP List formats not normally supported by TIdFTPList.DirectoryListing is initialized prior to use in List, or using the OnCreateFTPList event handler. DirectoryListing is freed in the Destroy method.自己去IndyProject.org下载Demo了,里面有FTP的例子的了例如
    procedure TMainForm.DirectoryListBoxDblClick(Sender: TObject);
    Var
      Name{, Line}: String;
    begin
      if not IdFTP1.Connected then exit;
      //Line := DirectoryListBox.Items[DirectoryListBox.ItemIndex];
      Name := IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].FileName;
      if IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].ItemType = ditDirectory then begin
        // Change directory
        SetFunctionButtons(false);
        ChageDir(Name);
        SetFunctionButtons(true);
      end
      else begin
        try
          SaveDialog1.FileName := Name;
          if SaveDialog1.Execute then begin
            SetFunctionButtons(false);        IdFTP1.TransferType := ftBinary;
            BytesToTransfer := IdFTP1.Size(Name);        if FileExists(Name) then begin
              case MessageDlg('File aready exists. Do you want to resume the download operation?',
                mtConfirmation, mbYesNoCancel, 0) of
                mrYes: begin
                  BytesToTransfer := BytesToTransfer - FileSizeByName(Name);
                  IdFTP1.Get(Name, SaveDialog1.FileName, false, true);
                end;
                mrNo: begin
                  IdFTP1.Get(Name, SaveDialog1.FileName, true);
                end;
                mrCancel: begin
                  exit;
                end;
              end;
            end
            else begin
              IdFTP1.Get(Name, SaveDialog1.FileName, false);
            end;
          end;
        finally
          SetFunctionButtons(true);
        end;
      end;
    end;
      

  16.   

    我装了 Indy9 ,但在 IdFTPList.pas 中根本没有找到任何 DirectoryListing 字样,
    IdFTP1->DirectoryListing 打出来就报错,好象根本没有这个方法!别人是怎么用的呢??奇怪···