Discuss this help topic in SecureBlackbox Forum

FTPS: Retrieve the file list

TElSimpleFTPSClient.ListDirectory method lists the remote directory contents. This is a high-level method which chooses the best listing command (MLSD is used, when available), changes working directory if needed (current directory is restored after the listing is obtained) and performs filtration of results. The method fills an array specified by Listing parameter with a list of TElFTPFileInfo objects. ListDirectory should be called once per enumeration: it returns the complete directory contents. Files are chosen by mask which can be a simple mask, set of masks or a regular expression (read more about file masks and regular expressions).

For more control over the process use MLSD(), GetFileList() or GetNameList() methods of TElSimpleFTPSClient class. All of these methods return the data via OnTextDataLine event. So you need to provide a handler for this event in order to obtain the data.

If the server supports MLSD command (this can be checked using ExtMLSTSupported property of TElSimpleFTPSClient class), you can use the reliable way to read the directory contents.

Call MLSD() method to retrieve the directory listing in standard-defined machine-parseable format. he method executes MLSD command of FTP protocol. MLSD command is similar to LIST, but returns the information in standard machine-parsable format. Note, that not all servers support MLSD command (which is an extension of the standard). To check if the command is supported, inspect the value of ExtMLSTSupported property. During execution of this method the TElSimpleFTPSClient.OnTextDataLine event is fired for each line of received reply. Overloaded methods return the listing via ResultList parameter, which can be a list of unparsed response line (the same as in OnTextDataLine event) or a list of TElFTPFileInfo objects. The entries of such listing can be parsed using ParseMLSDEntry() class/static method.

GetFileList() method returns the listing as returned by the file system (or the FTP server). Such listing can contain file name, access rights, size, various dates etc.. You can parse the entries of the listing using ParseFileListEntry() class method of TElSimpleFTPSClient class. The listing is system-dependent. Nowadays about 400 formats are known. TElSimpleFTPSClient class supports most commonly used Unix format and DOS/Windows format. You can parse other formats yourself.

GetNameList() method returns only file and directory names. This can be more handy than using GetFileList() and then parsing the result.

How To articles about client-side FTPS questions

Discuss this help topic in SecureBlackbox Forum