Board index » delphi » FTP Server problem when listing a directory

FTP Server problem when listing a directory

When I request a directory list from my server, I receive a error: "226
Closing DataConnection"

Here's my code, Im sure I must be missing something:

Client:
  slRet := TStringList.Create;
  try
    ftpClient.List(slRet, '*.*', True);     // <-- EXCEPTION HERE
    if ftpClient.DirectoryListing.Count > 0 then
      begin
         ....

Server:
procedure TfrmMyFiles.ftpServListDirectory(ASender: TIdFTPServerThread;
  APath: String; ADirectoryListing: TIdFTPListItems);
var
  itm: TIdFTPListItem;
  srList: TSearchRec;
  FileAttrs: integer;
begin
  if APath = '/*.*\' then APath := '*.*';

  APath     := ASender.HomeDir + APath;
  FileAttrs := (faDirectory + faArchive + faReadOnly);

  if FindFirst(APath, FileAttrs, srList) = 0 then
    begin
      repeat
        itm := ADirectoryListing.Add;
        if not ((srList.Name = '.') or (srList.Name = '..')) then
          if (srList.Attr and faDirectory) > 0 then   // Folder
            begin
              itm.ItemType := ditDirectory;
              itm.FileName := srList.Name;
            end
          else                                        // File
            begin
              itm.ItemType := ditFile;
              itm.FileName := srList.Name;
              itm.Size     := srList.Size;
              itm.ModifiedDate := FileDateToDateTime(srList.Time);
            end;
      until FindNext(srList) <> 0;

      FindClose(srList);
    end;
end;

The server code sems to complete fine  The ADirectoryListing collection sems
to be built fine.

No idea what's wrong.  This is my first FTP server.

Thanks.

 

Re:FTP Server problem when listing a directory


I still can't figure this out.  I cannot get the directory list to go back
to the client.  And I did verify the list was created and dropped in the
FDataChannelThread.  It seems to get blocked because of the 226 response
going back to the client.

Does this work?  or is it a bug?

Thanks.

Quote
"Matt" <mpeeb...@lenstar.com> wrote in message news:3c17c5c9$1_2@dnews...
> When I request a directory list from my server, I receive a error: "226
> Closing DataConnection"

> Here's my code, Im sure I must be missing something:

> Client:
>   slRet := TStringList.Create;
>   try
>     ftpClient.List(slRet, '*.*', True);     // <-- EXCEPTION HERE
>     if ftpClient.DirectoryListing.Count > 0 then
>       begin
>          ....

> Server:
> procedure TfrmMyFiles.ftpServListDirectory(ASender: TIdFTPServerThread;
>   APath: String; ADirectoryListing: TIdFTPListItems);
> var
>   itm: TIdFTPListItem;
>   srList: TSearchRec;
>   FileAttrs: integer;
> begin
>   if APath = '/*.*\' then APath := '*.*';

>   APath     := ASender.HomeDir + APath;
>   FileAttrs := (faDirectory + faArchive + faReadOnly);

>   if FindFirst(APath, FileAttrs, srList) = 0 then
>     begin
>       repeat
>         itm := ADirectoryListing.Add;
>         if not ((srList.Name = '.') or (srList.Name = '..')) then
>           if (srList.Attr and faDirectory) > 0 then   // Folder
>             begin
>               itm.ItemType := ditDirectory;
>               itm.FileName := srList.Name;
>             end
>           else                                        // File
>             begin
>               itm.ItemType := ditFile;
>               itm.FileName := srList.Name;
>               itm.Size     := srList.Size;
>               itm.ModifiedDate := FileDateToDateTime(srList.Time);
>             end;
>       until FindNext(srList) <> 0;

>       FindClose(srList);
>     end;
> end;

> The server code sems to complete fine  The ADirectoryListing collection
sems
> to be built fine.

> No idea what's wrong.  This is my first FTP server.

> Thanks.

Other Threads