CFtpClient::OpenDirectory Method  
 
INT OpenDirectory(
  LPCTSTR lpszDirectory  
);

The OpenDirectory method opens the specified directory on the server.

Parameters

lpszDirectory
Pointer to the name of the directory that will be opened. The format of the directory name must match the filename conventions used by the server. If a NULL pointer or an empty string is specified, then the current working directory is opened.

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

The OpenDirectory method opens the specified directory on the server using the LIST command. The contents of the directory can be read using the GetFirstFile and GetNextFile methods. The directory listing is returned on the data channel in one of several different formats. The library can recognize listing formats generated by UNIX, VMS and Windows servers, as well as those of other servers which emulate one of those common formats. Once the complete directory listing has been read, the directory must be closed by calling the CloseDirectory method.

Because the directory listing is returned on the data channel, a file transfer cannot be performed while the directory is in the process of being read by the client. Applications which need to collect a list of files to download should first open the directory, read the contents and store the file names in an array. After the directory has been closed, the application can then start transferring the files to the local system.

Some servers may not support file listings for any directory other than the current working directory. If an error is returned when specifying a directory name, try changing the current working directory using the ChangeDirectory method and then call this method again, passing NULL or an empty string as the lpszDirectory parameter.

To obtain a list of all files in a directory using a single function call, use the EnumFiles method. If the server lists files in a format that is not recognized by the library, the GetFileList method can be used to obtain an unparsed file listing from the server.

Example

if (pClient->OpenDirectory() != FTP_ERROR)
{
    FTPFILESTATUS ftpFile;
    BOOL bResult;

    bResult = pClient->GetFirstFile(&ftpFile);
    while (bResult)
    {
        // The ftpFile structure contains information about the file
        bResult = pClient->GetNextFile(&ftpFile);
    }

    pClient->CloseDirectory();
}

Requirements

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

See Also

ChangeDirectory, CloseDirectory, EnumFiles, GetDirectoryFormat, GetFileList, GetFileStatus, GetFirstFile, GetNextFile, SetDirectoryFormat