ChangeDirectory Method  
 

Change the current working directory on the server.

Syntax

object.ChangeDirectory( RemotePath )

Parameters

RemotePath
A string which specifies the directory on the server. The file naming conventions must be that of the host operating system.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

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.

See Also

CloseDirectory Method, GetDirectory Method, OpenDirectory Method, ReadDirectory Method