Back to product page

ListAttributes function


Lists the contents of a directory as a structure.

Type

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

Syntax

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

Remarks

The ListAttributes function will send a request to the server to retrieve a complete directory structure in an array of WIN32_FIND_DATA structures, rather than a line-by-line listing that needs to be parsed. As a result of this method call, the AttributesData callback will be invoked (possibly more than once if there are many files in the directory).

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, 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.

The code in this example will loop through all received items:
 
void SftpAttributesData(void *Sftp, int Count, WIN32_FIND_DATA **Items)
{
  char *it = (char *)Items;
 
  for (int i=0;i   {
     WIN32_FIND_DATA *dt = (WIN32_FIND_DATA *)it;
     SYSTEMTIME st;
     FileTimeToSystemTime(&dt->ftLastWriteTime, &st);
     ........
     ........
     it += sizeof(WIN32_FIND_DATA);
  }
  return;
}
 

To retrieve a full listing of files/directories on a given path (including size, permissions, dates...) you should use the ListDir function. To get names only, you can use ListNames.

Platforms

Windows