5

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.

kolrie
  • 235
  • 3
  • 12

2 Answers2

6

You could use 'scp':

On Server 1 do something like this:

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

More info with man scp.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • this will tranfer the file on the middle server and then upload it to destination server. kind of ... expensive, right? – user237419 May 11 '12 at 19:50
  • Thanks a lot for your input. It seems my original question was misleading. I can access Server 2 from Server 1 and vice-versa. Just can't SSH connect between the two. – kolrie May 11 '12 at 19:58
  • @malfaux: Yes, it's doubling the transfer. But in most cases, it's just much more quicker than your approach, which I would do for large files or over a slow link. – Sven May 11 '12 at 20:32
  • @SvenW oh? how is transferring 2x$N GB of data over 2 different links "much more quicker" than transferring $N GB of data over the same link? i'd say it's much more costly, time and money. unless you know he has fiber between s1 and s2 and s1 and s3 and a dial-up link between s2 and s3. is that your argument? I'm just curious what are you thinking. cheers! – user237419 May 12 '12 at 08:19
  • @malfaux: In most cases with a few GB of transfer, the copying would be done with my version of the command before I logged into two computers to initiate a transfer via `nc`. This is moot anyway, because in my networks, when a machine can talk to another via `nc`, it can talk to it via `ssh`. – Sven May 12 '12 at 09:26
5

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

user237419
  • 1,653
  • 8
  • 8