I am reposting a slightly edited version of this Ask Ubuntu question SCP with two different ports, as the answer there that works with command-line options only (without modifying ssh_config) no longer works for me.

How can I use scp command to copy files between two remote servers that use different ports from my local PC?


  • remote server 1 : IP= & port=6774
  • remote server 2 : IP= & port=6775


  • If I use
    scp -rp -P 6774 [email protected]:/home/denny/testapp1.txt  [email protected]:
    it gives an error:
    ssh: connect to host port 22: Connection refused
  • If I use
    scp -rp -P 6774 [email protected]:/home/denny/testapp1.txt -P 6775 [email protected]:
    it gives me this error:
    ssh: connect to host port 6775: Connection refused  
    ssh: connect to host port 6774: Connection refused  
    lost connection

1 Answer 1


Specify the ports in source and target URLs:

scp -3 scp://host1:port1//path/to/file  scp://host2:port2//path/to/file

You must log in to answer this question.

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