CFtpClient::Command Method  
 
INT Command(
  LPCTSTR lpszCommand,  
  LPCTSTR lpszParameter  
);

The Command method sends a command to the server, and returns the result code back to the caller.

Parameters

lpszCommand
The command which will be executed by the server.
lpszParameter
An optional command parameter. If the command requires more than one parameter, then they should be combined into a single string, with a space separating each parameter. If the command does not accept any parameters, this value may be NULL.

Return Value

If the method succeeds, the return value is the result code returned by the server. If the method fails, the return value is FTP_ERROR. To get extended error information, call GetLastError.

Remarks

This method should only be used when the application needs to send a custom, site-specific command or send a command that is not directly supported by this class. This method should never be used to issue a command that opens a data channel. If the application needs to transform data as it is being sent or received, and cannot use the GetFile or PutFile methods, then use the OpenFile method to open a data channel with the server.

By default, file names which are sent to the server using the Command method are sent as ANSI characters. If the Unicode version of the function is used, the file name will be converted from Unicode to ANSI using the current codepage. If the server supports UTF-8 encoded file names, the SetFileNameEncoding function can be used to specify that file names with non-ASCII characters should be sent as UTF-8 encoded values. It is important to note that this option is only available if the server advertises support for UTF-8 and permits that encoding type.

Because the Command method communicates directly with the server using the control connection, the idle timeout period configured with SetIdleTimeout applies to this method as well. If a session remains inactive for longer than the configured timeout, the server may close the connection before the command is sent or before a response is received. Adjusting the idle timeout can help prevent unexpected disconnects during periods of infrequent command activity, especially in interactive or long-running operations.

This method is not supported when using SFTP because that protocol does not provide a mechanism for sending arbitrary command strings. Unlike the FTP protocol, which uses a command-response model over a control channel, SFTP uses a structured binary protocol without support for custom commands. If this method is called while connected to an SFTP server, it will fail and return an error.

Requirements

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

See Also