0 votes
by (8.6k points)
edited

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

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (58.9k points)
edited

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 = "...";
ftp.SendCommand(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
Console.WriteLine(response.Description);

//If you want to write the entire response of the server, do:
Console.WriteLine(response.Raw);

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

...