CFtpServer::ChangeClientDirectory Method  
 
BOOL ChangeClientDirectory(
  UINT nClientId,  
  LPCTSTR lpszDirectory  
);

Change the current working directory for the specified client.

Parameters

nClientId
An unsigned integer which uniquely identifies the client session.
lpszDirectory
A pointer to a string which specifies the new current working directory for the client session. If this parameter is NULL or an empty string, the current working directory will be changed to the client home directory. If this parameter is not NULL, it must specify a directory that exists and is accessible by the server process.

Return Value

If the current working directory was changed, the return value is non-zero. If the client ID does not specify a valid client session, or the directory is invalid, this method will return zero.

Remarks

The ChangeClientDirectory method will change the current working directory for the specified client session. This method is called internally when the client sends the CWD or CDUP commands, however it may be explicitly used by the application to change the client's working directory in response to a server event.

This method cannot be used to change the current working directory for a client to an arbitrary directory outside of the server root directory. If the lpszDirectory parameter specifies a relative path (i.e.: a path that does not begin with a drive letter or leading path delimiter) then the new working directory will be relative to the current working directory. If an absolute path is specified, the absolute path must include the complete path to either the server root directory or the user's home directory, based on the permissions granted to the client session. If a path outside of the server root directory is specified, this method will fail with an access denied error.

Use caution when calling this method to override the directory specified by the client when it sends the CWD or CDUP commands. If your application changes the current working directory to one not specified by the client, it may cause unpredictable behavior in the client application because the actual path of the current working directory will not match the directory that was requested.

If this method is used to change the current working directory in response to the CWD command, you should not call the GetCommandParam method and pass the command parameter as an argument to this method. You must use the GetCommandFile method to obtain the directory name provided by the client prior to calling this method.

The application should never call the SetCurrentDirectory function in the Windows API to change the current directory for the process to the working directory of a client session. Because the server is multithreaded and each client session is managed in its own thread, an application using this library should avoid using relative paths.

Requirements

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

See Also

GetClientDirectory, GetClientHomeDirectory, GetCommandFile