How to send a specific command to FTP server

0 votes
asked Feb 21, 2012 by Rebex KB (8,430 points)
edited Feb 21, 2012

How can I execute a specific command on a FTP server with Rebex components?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Feb 21, 2012 by Tomas Knopp (58,890 points)
edited Feb 21, 2012

To send a command to the FTP server from Rebex ftp client, use methods SendCommand(string command) and ReadResponse() as in the following example:

//conect and login to the ftp server
Ftp ftp = new Ftp();
ftp.Connect("hostname", "port");
ftp.Login("username", "password");

//send the command, the capitalization does not matter
string command = "...";

//read the response from the server
FtpResponse response = ftp.ReadResponse();

// if the command was not succesfully understood or executed, throw an exception
if (response.Group != 2) 
  throw new FtpException(response);

//response.Description contains a short description of what happened

//If you want to write the entire response of the server, do:

Other method which can be used to send SITE commands is described at this forum post.