Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use SCP on my local server to copy a file from one remote server to another remote server (both remote servers use a custom port (xxxx)

I am trying:

scp -r -P xxxx

But I get the following error:

ssh: connect to host port 22: Connection timed out

Any suggestions?

share|improve this question

migrated from Nov 7 '09 at 0:07

This question came from our site for professional and enthusiast programmers.

I presume that you can ssh to normally? – Benj Nov 5 '09 at 10:10
Yeah, I can ssh to all servers from all servers – Lizard Nov 5 '09 at 10:14
Cross posted here:… – Dennis Williamson Nov 5 '09 at 11:55
up vote 12 down vote accepted

did you check that direct authentication works from first remote host to the second one?

scp user@host:/file user@otherhost:/otherfile is shorthand for

ssh user@host scp /file user@otherhost:/otherfile

which leeds me to think:

ssh -p XXX user@host scp -P XXX /file user@otherhost:/otherfile might work.

share|improve this answer
Yeah, i have ssh'd to both all servers from each server :( – Lizard Nov 5 '09 at 10:10
Good point, just because you can see xxx.222 doesn't mean that xxx.111 can. – Benj Nov 5 '09 at 10:11
It is a good point, but I have already checked that, any other suggestions? – Lizard Nov 5 '09 at 10:13
The ssh then the scp does what i need it to. – Lizard Nov 5 '09 at 10:18

It seems like scp doesn't realize that the special port should also be used on the second server. You could try to explicitly call ssh to start the remote scp transfer:

ssh -P xxxx user@host scp -P xxxx /file user@otherhost:/otherfile
share|improve this answer

Define the servers in your .ssh/config file, for example:

Host foobar
User youruser
Port 2222
Hostname the.real.hostname

Host foobar2
User youruser
Port 2222
Hostname the2.real.hostname

You can then simply do:

scp foobar:file foobar2:

and it will use the defined custom ports.

share|improve this answer

I've got remote servers that cannot see each other, but my local server can see both. The ssh daemon in the remote servers are listening in different non-standard ssh ports. This is how I get this done:

ssh -p 111 userA@remote1 'cat myfile' | ssh -p 222 userB@remote2 'cat - > myfile'

The second ssh command asks for the password first, then remote1 asks for password for userA. You may have this automated if you have set up ssh authorized keys, which is not the case in my environment.

share|improve this answer

You must log in to answer this question.

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