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.