14

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.

3 Answers 3

4

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.

22

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.

3
  • My scp does not implement -3 when I execute the comand i get scp: illegal option -- 3 usage: scp [-1246BCEpqrv] ...
    – JorgeO
    Jul 26, 2011 at 16:50
  • 1
    That's correct. -3 is only available in the latest version of OpenSSH, which I am not sure that Debian has implemented yet.
    – Rilindo
    Jul 26, 2011 at 16:51
  • Ahh, sorry about that. Updated the answer regarding version requirement.
    – andol
    Jul 26, 2011 at 16:58
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.

2
  • Didn't know about the && operator. Better than using ;
    – JorgeO
    Jul 26, 2011 at 17:45
  • 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
    Jul 17, 2014 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .