CFtpClient::FileList Method  
 
INT FileList(
  LPCTSTR lpszDirectory,  
  DWORD dwOptions  
);

The FileList method begins listing files in the specified directory.

This method has been deprecated and should no longer be used in new applications.

Parameters

lpszDirectory
A null-terminated string that specifies the name of a directory and/or a wildcard file mask. The format of the directory name must match the file naming conventions of the server. If this parameter is NULL or points to an empty string, the current working directory will be used.
dwOptions
An unsigned integer that specifies one or more options. This parameter may be any one of the following values:
Value Description
FTP_LIST_DEFAULT This option specifies the server should return a complete listing of files in the specified directory with as much detail as possible. This typically means that the file size, date, ownership and access rights will be returned to the client. Specifying this option causes the client to send the LIST command to the server. Information about the files are returned in lines of text, with each line terminated by carriage return and linefeed (CRLF) characters. The exact format of the data returned is specific to the server operating system.
FTP_LIST_NAMEONLY This option specifies the server should only return a list of file names, with no additional information about the file. Specifying this option causes the client to send the NLST command to the server. Each file name is terminated by carriage return and linefeed (CRLF) characters.

Return Value

If the method succeeds, the return value is the server result code. If the method fails, the return value is FTP_ERROR. To get extended error information, call GetLastError.

Remarks

This method is provided as an alternative to the preferred method OpenDirectory. It is useful if the application only needs a list of file names without additional information such as size or permissions, or if the server returns file listings in a format that is not supported by the library. In this case, the application will have to parse the data returned by successive calls to the Read method.

Each call to the Read method will return a string that will be terminated with a line termination sequence (a linefeed or carriage return, linefeed pair). The string will not be null-terminated. Complete file listing from most servers will contain the information for a single file on a single line, but that is not always true. This method cannot be used with SFTP (SSH) connections.

To obtain an unparsed list of files from the server, it is recommended that you use the GetFileList method.

Example

if (pClient->FileList(szDirectory, FTP_LIST_NAMEONLY) == FTP_ERROR)
{
    DWORD dwError = pClient->GetLastError();
    if (pClient->GetErrorString(dwError, szErrMsg, BUFSIZE) !=0)
        fprintf(stderr, "%s\n", szErrMsg);
    else
        fprintf(stderr, "Unknown error %08x\n", dwError);
    return;
}

do
{
    if ((nRead = pClient->Read((LPBYTE)szBuffer, BUFSIZE)) > 0)
    {
        *(szBuffer + nRead) = '\0'; // null-terminate the data
        printf("%s",szBuffer);
    }
}
while (nRead > 0);

CloseDirectory();
      

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csftpv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also