+1 vote
by (640 points)
edited

The documentation in section about Ftp::GetNameList() method says:

Actual behaviour of NLST command varies from server to server, because the RFC is not clear in explaining what it should do. Some servers return the names of both files and directories, others return files only or even report error if the current directory is empty. Using GetList is a better choice in most cases.

Is this right? The rfc says

Since the information on a file may vary widely from system to system, …

about LIST command, and the result of NLST command is simple:

The server will return a stream of names of files and no other information …

What the better (works on a lot of servers) way to get a file names and their sizes: GetList() or GetNameList() + GetFileSize()? I'm interesting about Ftp and Sftp.

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (13.0k points)
edited
 
Best answer

FTP: NSLT

The situation with NLST seems to be clear and unambiguous ... but is not. Imagine the following command:

   NSLT dir

some servers respond with something like this

   file1
   file2

while other servers respond with different output

  dir/file1
  dir/file2

FTP: GetNameList + GetFileSize

GetNameList works almost universally. GetFileSize is not supported by some FTP servers. And in some FTP servers the SIZE commands returns 0 for directories (so it's hard to decide whether a FTP item is file or directory).

SFTP: GetNameList, GetList and GetRawList

There is only one method for getting a directory content in the SFTP protocol. Those three methods are provided only for convenience and in order to have API similar to FTP component.

Best way how to get a directory list

FTP:

The best way would be calling Ftp.GetList() and let the parser handle all problems. If the format cannot be parsed then call the Ftp.GetRawList and mail the output to support@rebex.net. We'll be happy to enhance the built-in parser so it can handle this new format.

You can also subscribe to FtpItem.ItemParse event and provide your own parser. Sample parser which processes *nix access rights can be found in Rebex FTP Console Client sample.

SFTP:

Sftp.GetList() should work everywhere.

Applies to:

by (640 points)
Thanks for the great answer!
by (13.0k points)
Thanks. Good questions inspire good answers ;-)
...