InetFTPCommand
int InetFTPCommand (int FTPHandle, const char *command, char responseBuffer[], size_t responseBufferSize, InetFTPCommandDataCallbackType callback);
Purpose
Sends and processes an FTP protocol command. Pass a command that is valid for your FTP server. If the command requires data transmission or reception pass a valid callback function, otherwise, pass NULL in the Callback parameter. The following code is an example of how to call this function:
static int CVICALLBACK FTPCallback(int ftpHandle, int replyCode)
{
char buffer[1024];
int error;
while (1)
{
/* read data from server */
error = InetFTPReceiveData(
ftpHandle, buffer, sizeof(buffer) - 1);
/* if error occurred return the error */
if (error < 0)
return error;
/* stop reading if there is no more data */
if (error == 0)
break;
/* NUL-terminate the buffer and print the data */
buffer[error] = '\0';
printf(buffer);
}
return 0;
}
void main(void)
{
char buffer[1024];
int ftp;
/* open FTP connection */
ftp = InetFTPLogin("ftp.ni.com", "anonymous", "me@ni.com");
/* list the contents of the root directory */
/* LIST returns the listing in the data channel. */
InetFTPCommand(ftp, "LIST /", NULL, 0, FTPCallback);
/* get and print current FTP server status */
/* STAT returns status in control channel. It does not */
/* use data channel - so callback should be NULL. */
InetFTPCommand(ftp, "STAT", buffer, sizeof(buffer), NULL);
puts(buffer);
/* close FTP server */
InetFTPClose(ftp);
}
Parameters
Input | ||
Name | Type | Description |
FTPHandle | int | A handle returned by the InetFTPLogin or InetFTPLoginEx function. The handle identifies an active FTP connection. |
command | const char * | The FTP protocol command to send to the FTP server. |
responseBufferSize | size_t | Pass the size of the response buffer. |
callback | InetFTPCommandDataCallbackType | The callback function that the Internet Library calls to receive and send data associated with the command, say, for commands like LIST, RETR, STOR, etc. Pass 0 if your command does not require data transmission or reception, say, for commands like HELP, STAT, SYST, etc.
The callback function, type InetFTPCommandDataCallbackType, takes the following form: int CVICALLBACK Function (int ftpHandle, int replyCode); The callback function receives the FTP handle and reply code of the associated command. Check the reply code to determine if data communication is necessary. The callback function must return 0 to indicate successful data processing; the InetFTPCommand function receives the final status of the command and returns it. If no data communication is needed, the callback function must return a non-zero positive value. The callback function returns a negative error code if an error occurred in the callback function. In the callback function, you can call only the following FTP functions from this library: InetFTPReceiveData and InetFTPSendData. |
Output | ||
Name | Type | Description |
responseBuffer | char [] | Pass a buffer to receive the response from the server. You can pass 0 if this information is not required. Passing a valid buffer is useful to retrieve the output of commands like HELP, STAT, SYST, etc. |
Return Value
Name | Type | Description |
result | int | Return value indicating whether the function was successful. A negative number indicates that an error occurred. |
Additional Information
Library: Internet Library
Include file: cvintwrk.h
LabWindows/CVI compatibility: LabWindows/CVI 9.0 and later