SCP from one external server to another

12

4

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 root@xxx.xxx.xxx.111:/home/myimages/images.tar.gz root@xxx.xxx.xxx.222:/home/myimages/images.tar.gz

But I get the following error:

ssh: connect to host xxx.xxx.xxx.222 port 22: Connection timed out

Any suggestions?

Lizard

Posted 2009-11-05T10:02:47.653

Reputation: 325

I presume that you can ssh to xxx.xxx.xxx.222 normally? – None – 2009-11-05T10:10:20.590

Yeah, I can ssh to all servers from all servers – Lizard – 2009-11-05T10:14:10.157

Cross posted here: http://serverfault.com/questions/81650/scp-from-one-external-server-to-another

– Paused until further notice. – 2009-11-05T11:55:22.647

Answers

17

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.

jhwist

Posted 2009-11-05T10:02:47.653

Reputation: 514

1Yeah, i have ssh'd to both all servers from each server :( – Lizard – 2009-11-05T10:10:51.073

Good point, just because you can see xxx.222 doesn't mean that xxx.111 can. – None – 2009-11-05T10:11:46.707

It is a good point, but I have already checked that, any other suggestions? – Lizard – 2009-11-05T10:13:18.377

The ssh then the scp does what i need it to. – Lizard – 2009-11-05T10:18:46.790

3

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.

sameproblemIhad

Posted 2009-11-05T10:02:47.653

Reputation: 31

3

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.

Joss

Posted 2009-11-05T10:02:47.653

Reputation: 61

3

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

sth

Posted 2009-11-05T10:02:47.653

Reputation: 559