Sending custom commands to an FTP server

Explicitly sending commands to an FTP server is usually not necessary. Almost all commands that could conceivably be sent to an FTP server are encapsulated by high-level methods. However, to send a command to an FTP server, simply call the SendCommand method, and to get the response from the FTP server, call the ReadResponse method.

The example below sends the "FEAT" command to an FTP server and prints out the response:

C#:

// Create a new Ftp instance.
Ftp client = new Ftp();
// Connect to the FTP server.
client.Connect("server");
// Authenticate.
client.Authenticate("username", "password");
// Send command
client.SendCommand("FEAT");
// Print out the response
FtpResponse res = client.ReadResponse();
Console.WriteLine(res.RawResponse);
// Disconnect.
client.Disconnect();

VB.NET

' Create a new FtpClient instance.
Dim client As New Ftp()
' Connect to the FTP server.
client.Connect("server")
' Authenticate.
client.Authenticate("username", "password")
' Send command
client.SendCommand("FEAT")
' Print out the response
Dim res As FtpResponse = client.ReadResponse()
Console.WriteLine(res.Text)
' Disconnect.
client.Disconnect()