The ListDirectory or GetFileList methods return 0 elements, though the file download was successful. What's wrong?

Background

The FTP protocol (RFC 959) doesn't have a uniform way to get the listing of the directory.

The LIST command offered by the FTP protocol returns some text strings that describe directory contents. The format of those strings is completely undefined. There exist over 400 (or maybe even more) formats used by different servers. The most common formats are the Unix format and DOS/Windows formats, but even then you can see differences that can make it impossible to parse the result.

The GetFileList method uses the LIST command, the results of which are reported via the OnTextDataLine event. You can then use the ParseFileListEntry method (it supports the DOS/Windows and Unix formats) to parse the output. If ParseFileListEntry fails, you still can write your own parser or plug in an external library for parsing the listing.

Extensions to the FTP standard introduced the MLST/MLSD commands (MLST returns information about one file via command channel and MLSD returns a directory listing via data channel), which return the result in a predefined format that machines can parse. To work with this extension command, use the MLSD and ParseMLSDEntry methods of TElSimpleFTPSClient. Note that not all servers support MLSD. If the extension command is supported, this support is reported via the response to the FEAT command. The FEAT command is handled by TElSimpleFTPSClient internally, and the ExtMLSTSupported property is set to true if the server reports support.

ListDirectory is a high-level method that attempts to use the MLSD command when available; otherwise, it uses the LIST command.

In this particular case, the server neither supports the MLSD command nor provides the listing in one of the common/supported formats.

Solution

To solve the problem, use the sample in the <SecureBlackbox>\Samples\<language>\FTPSBlackbox\Client folder to connect to the server and try to list the directory. Then check the log produced to see what response to the FEAT command is given by the server and what format the listing is in. Then you can decide what to do next.

Ready to get started?

Learn more about SecureBlackbox or download a free trial.

Download Now