More .NET components

Advanced FTP features

Server-to-server transfers (FXP) #

Server-to-server transfer (also known as FXP) makes it possible to transfer files from one FTP server to another FTP server directly, without copying them to the FTP client which controls the transfer.

CSharp

// connect to the source FTP server
var ftp1 = new Rebex.Net.Ftp();
ftp1.Connect(hostname1, port1);
ftp1.Login(username1, password1);

// connect to the destination FTP server
var ftp2 = new Rebex.Net.Ftp();
ftp2.Connect(hostname2, port2);
ftp2.Login(username2, password2);

// copy a single file to the destination server
ftp1.CopyToAnotherServer(ftp2, "/Incoming/file1.txt", "/MyData/file1.txt");

// disconnect
ftp1.Disconnect();
ftp2.Disconnect();

VisualBasic

' connect to the source FTP server
Dim ftp1 As New Rebex.Net.Ftp()
ftp1.Connect(hostname1, port1)
ftp1.Login(username1, password1)

' connect to the destination FTP server
Dim ftp2 = New Rebex.Net.Ftp()
ftp2.Connect(hostname2, port2)
ftp2.Login(username2, password2)

' copy a single file to the destination server
ftp1.CopyToAnotherServer(ftp2, "/Incoming/file1.txt", "/MyData/file1.txt")

' disconnect
ftp1.Disconnect()
ftp2.Disconnect()

FTP servers that support the server-to-server transfers usually have it disabled by default. To utilize FXP, you first need to enable it.

Tip: Server-to-server transfers can also be used for copying files to another location at the same server. Alternatively, a user-defined SITE command (if supported by the FTP server) can be used for the same purpose.

Server-specific commands (SITE command) #

The SITE command (available through Ftp.Site method) can be used to execute a server-specific command. Many FTP server have their own set of specific SITE commands, and some servers make it possible to execute user-defined SITE commands as well.

CSharp

// change access rights to a file on unix-like FTP server
ftp.Site("CHMOD 777 file1.txt");

// show current user's group membership
string result = ftp.Site("GROUPS");
Console.WriteLine(result);

VisualBasic

' change access rights to a file on unix-like FTP server
ftp.Site("CHMOD 777 file1.txt")

' show current user's group membership
Dim result = ftp.Site("GROUPS")
Console.WriteLine(result)
Tip: To obtain a list of SITE commands supported by your server, call Ftp.Site("HELP"). This works on most FTP servers.

Custom FTP commands #

Any FTP command can be executed using Ftp.SendCommand method. Use ReadResponse to read the command's result.

CSharp

// send the FEAT command (get a list of server features)
ftp.SendCommand("FEAT");

// read the response
var response = ftp.ReadResponse();
Console.WriteLine(response.Raw);

VisualBasic

' send the FEAT command (get a list of server features)
ftp.SendCommand("FEAT")

' read the response
Dim response = ftp.ReadResponse()
Console.WriteLine(response.Raw)

SendCommand method can be used be execute the COMB command, available on some FTP servers for combining multiple parts of a single into one large file.

Tip: SendCommand method corresponds to command-line FTP client's quote command.

Uploading files with server-generated unique name (STOU command) #

Ftp.PutUniqueFile uploads a file or stream to the FTP server, with a unique remote file name assigned by the server. The assigned file name is returned by the server.

Note: This method uses STOU command, which is not supported by all FTP servers.