我的代码如下:
AFTP.ChangeDir(ADirectory);
       
       aftp.DirectoryListing.Create;
      AFTP.TransferType := ftASCII;
      AFTP.List(nil);      aftp.DirectoryListing.ListFormat:=flfUnix;
      
      dirlist.ListFormat := aftp.DirectoryListing.ListFormat;
      DirList := AFTP.DirectoryListing;为什么在运行到DirList := AFTP.DirectoryListing;这一句的时候报错:exception class EIDInvalidFTPListingFormat with message:Unknown FTP listing format求高手解答.

解决方案 »

  1.   

    完整代码
    procedure TForm1.FTPDirToTreeView(AFTP: TIdFTP; ATree: TTreeView;
                               const ADirectory: String; AItem: TTreeNode;
                               AIncludeFiles:Boolean);
    var
      TempItem: TTreeNode;
      I: Integer;
      DirList: TIdFTPListItems;
      DirItem: TIdFTPListItem;
      LS: TStringList;
    begin
      LS := TStringList.Create;
      DirList:= TIdFTPListItems.Create;
      try
        LS.Sorted := True;
        ATree.Items.BeginUpdate;
        try
          if (ADirectory <> '') then
            AFTP.ChangeDir(ADirectory);
          AFTP.TransferType := ftASCII;
          AFTP.List(nil);
          showmessage(aftp.DirectoryListing.Items[0].Text);
          DirList := AFTP.DirectoryListing;
          for i := 0 to DirList.Count - 1 do
          begin
          try
            DirItem := DirList.Items[i];
            if (DirItem.ItemType = ditDirectory) then
            begin
              TempItem := ATree.Items.AddChild(AItem, Trim(DirItem.FileName)+ '/');
              LS.AddObject(Trim(DirItem.FileName), TempItem);
            end
            else
            begin
              if (AIncludeFiles) then
                ATree.Items.AddChild(AItem, DirItem.FileName);
            end;
          except
          end;
          end;      for i := 0 to LS.Count - 1 do
          begin
            FTPDirToTreeView(AFTP, ATree, ADirectory +
            LS.Strings[i] + '/', TTreeNode(LS.Objects[i]), AIncludeFiles);
          end;
        finally
          ATree.Items.EndUpdate;
        end;
      finally
        LS.Free;
      end;
    end;
      

  2.   

    已经解决了,原来跟ftp server的目录样式有关,必须设置为unix风格才可以.