Best way to transfer files from one server to another using a third server

Here's the scenario:

                   ssh  +------------+
                  +---->|  Server 2  |
 +------------+   |     +------------+
 |  Server 1  +---+
 +------------+   |     +------------+
                  +---->|  Server 3  |
                   ssh  +------------+

I have SSH access from Server 1 to both Server 2 and Server 3 (but not from Server 2 to Server 3 nor the other way around).

I want to transfer a rather large file from 2 to 3 and would like to know what's the fastest way to do so by having 1 acting as the orchestrator.

UPDATE: I do have connectivity between the two servers, just not SSH credentials from/to the servers.


Solution 1:

you can do the transfer directly between the 2 servers:

on the server you want to transfer to, start nc in listen mode on some random port:

ssh dst-server 'exec 1>/tmp/bah; nc -l -p 34001'

on the server you want to download from, transfer with nc in client mode. you can use compression to, just create a gzip pipe:

ssh source-server 'nc dst-server 34001 < ./bah'

you'll find your file in /tmp/bah

Solution 2:

You could use 'scp':

On Server 1 do something like this:

scp  user1@server2:/path/filename user3@server3:/path 

More info with man scp.