Back to product page

ListDir function


Lists the contents of a directory on the server.

Type

A Long value. If successful, 0 is returned, otherwise error as specified here

Syntax

  • C
long Sftp_ListDir(void *Sftp, char *RemotePath);
The ListDir(void *Sftp,char *RemotePath) syntax has these parts:
void *SftpHandle of the created Sftp instance.
char *RemotePathFull path to a file on the server.

Remarks

The ListDir function will send a request to the server to retrieve a FULL listing for the directory specified by the RemotePath argument. Once the server sends data, the ListItems callback will be invoked (possibly more than once!) containing a list of files sent by the server, each one on a separate line, split by a CRLF sequence. The ListItems event is fired more than once if the total number of files is too large to be handled by one SFTP packet. So you should wait for the Done callback before declaring the listing as finished.

Once completed, the Done callback will be called. If no error occurs, the ErrorCode argument in the Done callback will be set to 0 (zero). If an error occurrs, the ErrorCode will hold the number of the error and ErrorText will contain a description of the error.

No wildcards can be used with the RemotePath argument. The RFC protocol specification for SFTP does not allow them.

To get filenames (and directory names) only for specific path, you can use the ListNames function. To retrieve the structure of a directory inside a ready-parsed collection of WIN32_FIND_DATA structures, you should use the ListAttributes function.

Platforms

Windows