Transfer Files From Ftp/Sftp To Ftp/Sftp

0 votes
asked Jan 6, 2014 by Tim (390 points)
edited Apr 4, 2014

Is there a method to directly transfer files between 2 ftp servers without having to download locally and then push to the second site?

Applies to: Rebex FTP/SSL, Rebex SFTP

2 Answers

+1 vote
answered Jan 6, 2014 by Jan Sotola (16,580 points)
edited Jan 6, 2014
 
Best answer

1) For the FTP protocol, it is possible to use the CopyToAnotherServer method on some FTP servers. It utilizes the FXP functionality, which should be supported by the source FTP server software.

// connect to the source server
Ftp session1 = new Ftp();
session1.Connect(server1);
session1.Login(username1, password1);

// connect to the destination server
Ftp session2 = new Ftp();
session2.Connect(server2);
session2.Login(username2, password2);

// copy a single file from server1 to server2
session1.CopyToAnotherServer(session2, sourcePath, destinationPath);

Please note that even if the FTP server supports the server-to-server transfers (FXP), it is usually disabled by default.

2) For the SFTP protocol, there is unfortunately nothing like the FXP technology.

commented Jan 6, 2014 by Tim (390 points)
edited Jan 6, 2014

Thanks Jan. Am I reading that correctly that it will only copy one individual file?

commented Jan 6, 2014 by Jan Sotola (16,580 points)
edited Jan 6, 2014

Yes. Unfortunately, multiple-file operations (using wildcards or filesets) are not supported by the CopyToAnotherServer method.

commented Jan 6, 2014 by Tim (390 points)
edited Jan 6, 2014

Ok, I can work with that if it's possible to zip the files in the directory before transfer and unzip on arrival at destination. Using the rebex package is it possible to do that? If so do you have a link to a sample

commented Jan 6, 2014 by Tim (390 points)
edited Jan 6, 2014

Or maybe the correct question is, is this the right way to go to conduct transfers between 2 ftp servers. Should I be using a memorystream to conduct the transfers between 2 servers? I am using ftp/ftps protocols

commented Jan 6, 2014 by Jan Sotola (16,580 points)
edited Jan 6, 2014

Zipping of several files is not possible when using server-to-server transfer. The transfer is controlled by pure FTP commands and there is no FTP command for zipping files on the remote server.

Server-to-server transfer is advantageous when your FTP client has a slow connection to FTP server(s), while the connection between servers is fast.

If your client computer has a quite fast connection to both FTP servers and you need to transfer multiple files, I'd recommend to download the files to a temporary folder on your client computer and then upload them to the target FTP server. You can use the Upload method with the TransferMethod.Move argument to atomically delete files from the temporary folder just after uploading.

A memorystream cannot be used in multiple-file Rebex operations since we don't provide any mechanism to wrap several files into a single stream.

commented Jan 6, 2014 by Tim (390 points)
edited Jan 6, 2014

Thanks, That was what my research was showing too. I was hoping to bypass local storage even if it was temporary but it's nothing that I can't work with. I just need to keep on top of the network team to ensure they don't continue to allow the drives to get full so I can't do the transfers. Maybe I should even add that as a pretest before the transfer attempt. Thanks again Jan very helpful.

0 votes
answered Apr 3, 2014 by vsat (230 points)
edited Apr 4, 2014

What is the methods to perform sftp-syncrhonous file transfer()

commented Apr 4, 2014 by Tomas Knopp (58,890 points)
edited Apr 4, 2014

See list of file transfer synchronous methods available in Rebex SFTP:

for multi file operations there are these synchronous methods:

...