SCP File Transfer Between Two Networks

file-transferscp

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.

Best Answer

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.

Related Question