Ubuntu – Transfer files between two remote SSH servers

cajanautilusnemosshtransfer

Is there an easy way to transfer files between two SSH/SFTP servers? The perfect solution would be FileZilla, but it only lets you create a connection between local and remote, but not between remote and remote.

Theoretically I could open two Nautilus windows and connect to some ssh://server1/path/to/folder and ssh://server2/path/to/folder and then just pull the files from one to the other side. My experience is that this is very unstable. Transmitting files in size sum of i.e. 10MB is no problem, but transferring i.e. 10GB often resulted in Nautilus hanging itself up and remaining there in need of ps -e | grep nautilus -> kill -9 <pid>. I also tested the same thing with Nemo and Caja. While Nemo tends to be more stable than the two others, it still is not perfect and also breaks from time to time. FileZilla is extremely stable, never really got it to break, but it is not very flexible due to the mentioned fact that it can only connect to a single SSH server.

Of course I could also mount a folder with sshfs, but this is kind of an inconvenient solution. Too much pre-work to do to get a simple transfer running.

Is there any app that can handle transfers between two SSH servers without breaking? Perfect would be something like FileZilla, that picks up the job again if the connection got interrupted.

Best Answer

If you are on an Ubuntu version that is still supported, then your scp command will provide the -3 switch which enables copying files from remote1 to remote2 via localhost:

me@local:~> scp -3 user1@remote1:/path/to/file1 user2@remote2:/path/to/file2

You can also omit the -3 switch, but then you will need the public key (id_rsa.pub) of user1@remote1 in the file authorized_keys of user2@remote2:

me@local:~> scp user1@remote1:/path/to/file1 user2@remote2:/path/to/file2

scp then under the hood does a ssh user1@remote1 first and from there scp /path/to/file1 user2@remote2:/path/to/file2. That's why the credential must be distributed different from the -3 solution.

In other words:

  • scp -3 remote1:file1 remote2:file2 transfers the file from remote1 to localhost and then back to remote2. The data travels remote1 → localhost → remote2. The localhost is the 3rd party in this scenario, hence -3. For this to work, you will need the credentials from localhost on both remote1 and remote2 because localhost connects to both of them.

  • scp remote1:file1 remote2:file2 copies the file directly from remote1 to remote2 at the speed with wich they are connected to each other. localhost is not involved here (besides issuing the command). The data travels remote1 → remote2. For this to work, you will need the credentials from localhost only on remote1 but additionally you need the credentials of remote1 on remote2 because localhost connects to remote1 only and then remote1 connects to remote2.

If possible I would choose the second approach. As some comments already say: usually often the network cable between remote1 and remote2 is far thicker than the cable between them and localhost.

Related Question