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

The ChangeDirectory method changes the current working directory for the client session.

Parameters

lpszDirectory
Points to a string that specifies the name of the directory. The file pathing and name conventions must be that of the server.

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

When using the FTP or FTPS protocols, this method sends the CWD (Change Working Directory) command to the server to change the current working directory. The user must have sufficient permissions to access the specified directory, and the operation will fail immediately if access is denied.

When using the SFTP protocol, there is no direct equivalent to the FTP CWD command. SFTP operates on fully qualified paths rather than maintaining a persistent current working directory on the server. To provide consistent behavior across protocols, this method simulates a working directory by normalizing the specified path and verifying that it refers to a valid directory on the server. If the path is valid, it is stored internally and used as the base path for subsequent file operations.

Because this behavior is implemented client-side, changing the working directory in an SFTP session does not affect the server state and is only meaningful within the context of the current connection. Additionally, permission-related errors may not be detected when this method is called. Instead, they may occur later when attempting to enumerate the directory or perform file operations within it.

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

ChangeDirectoryUp, CloseDirectory, Command, GetDirectory, GetFirstFile, GetNextFile, GetResultCode, GetResultString, OpenDirectory