SCP between two networks

12

3

I need to transfer a file between two computers that are not connected to the same network. I got a third computer that can see both networks through a VPN.

From the third computer, I can do:

scp root@firstcomputer:./file ./

And finish the transfer with the following sentence:

scp ./file root@secondcomputer:./

But I cannot do it in just one line, as follows:

scp root@firstcomputer:./file root@secondcomputer:./

The error response is

ssh: connect to host secondcomputer port 22: No route to host
lost connection

I realize that is probably because firstcomputer cannot see secondcomputer. Is it possible to give SCP a param that deals with the fact that the machine that runs the SCP program is the only one who can see both computers?

By the way, the third computer is a Mac with Lion and the fist and second are running Debian.

JorgeO

Posted 2011-07-26T16:34:52.077

Reputation: 223

Answers

3

You should be able to use an SSH tunnel.

Assuming you're trying to transfer a file from a remote computer ("remote") to your local computer ("local"), establish the tunnel via the third computer ("gateway") by typing this on your local computer:

ssh -fNL 12345:remote:22 gatewaylogin@gateway

Then you can run an unlimited amount of SCP commands on this tunnel (still typing on your local computer):

scp -P 12345 remotelogin@localhost://path/to/remote/file /local/path/where/you/want/file

I just tested this on my network, and it worked perfectly.

The above method is fine if the remote network is secure, but if it is not secure, you'd need to establish a tunnel between local and gateway, and another tunnel between gateway and remote, linking the two by a common port number.

mantipula

Posted 2011-07-26T16:34:52.077

Reputation: 46

21

The scp option -3 ought to be what you are looking for. To put it in your example:

scp -3 root@firstcomputer:./file root@secondcomputer:./

Note that the -3 option was first introduced in OpenSSH 5.7, which was released early 2011.

andol

Posted 2011-07-26T16:34:52.077

Reputation: 346

My scp does not implement -3 when I execute the comand i get scp: illegal option -- 3 usage: scp [-1246BCEpqrv] ... – JorgeO – 2011-07-26T16:50:40.270

1That's correct. -3 is only available in the latest version of OpenSSH, which I am not sure that Debian has implemented yet. – Rilindo – 2011-07-26T16:51:57.340

Ahh, sorry about that. Updated the answer regarding version requirement. – andol – 2011-07-26T16:58:09.380

1

You can try this:

root@firstcomputer:./file /tmp && scp /tmp/file root@secondcomputer:./ && rm /tmp/file

This will copy the file into the /tmp directory on the third computer and if it is successful, it will recopy that file to the secondary computer and then clean up itself. Since you are using the && operator, each command will only execute if the prior command is successful.

Rilindo

Posted 2011-07-26T16:34:52.077

Reputation: 166

This is the same technique that the original question used in the first example, which was trying to be avoided (copy from computer A to local machine, then copy local file to computer B). – Jason C – 2014-07-17T05:34:46.427

Didn't know about the && operator. Better than using ; – JorgeO – 2011-07-26T17:45:22.250