SCP between two different servers with two different ports

remotescp

The thing is, you can specify a port to SCP, and you can transfer stuff from a remote host to another.

If both hosts use different ports on SSH (i.e. 2203 and 2541), how can I specify these ports to the SCP command?

I know I can do

scp -P <port> host1:/file host2:/file

But that port will apply to both hosts.

So… how can I specify two different ports for the two different hosts?

Best Answer

After tink's comment: I think this may not apply to Linux, but to BSD systems:

The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]

so you can run:

scp scp://user1@host1:port1/path/to/file1 scp://user2@host2:port2/path/to/file2

And to copy between two remote hosts through the local host add "-3":

scp -3 scp://user1@host1:port1/path/to/file1 scp://user2@host2:port2/path/to/file2
Related Question