Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The following command is working as expected.

ssh soak@10.10.10.11 "ssh soak@10.199.199.191 'cat test.txt'" > /home/shantanu/test.txt

What I need to do is to copy the entire directory instead of a single file.

Is it possible to use rync with SSH tunneling?

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

You could pipe tar.

eg.

ssh soak@10.10.10.11 "ssh soak@10.199.199.191 'tar cf - test_directory'" | tar xf -
share|improve this answer
add comment

You can use scp to copy single or multiple files and also use rsync with an ssh transport:

scp -r localdirectoryname username@hostname:/remotepath

and

rsync -av localdirectory username@hostname:/remotepath 

Both programs also work the other way round, with the remote part as the origin and the local as the destination.

See man scp and man rsync.

Edit

If you indeed need an intermediate server, you could use ssh port forwarding:

In one shell, use this command to establish a port forwarding:

ssh -NL 10022:10.199.199.91:22 soak@10.10.10.11

This connects port 10022 on your local machine with port 22 on 10.199.199.91, but won't open a shell, instead just blocks until you terminate it.

Afterwards, on another shell/xterm, you can use either

scp -r -P 10022 localpath soak@localhost:/remotepath 

but have to be aware that soak@localhost actually points to soak@10.199.199.191 when entering your credentials.

Edit 2, now featuring rsync

As you specifically asked about rsync, here is how to use rsync instead of scp. It requires the same port forwarding enabled as the scp variant:

rsync -av --rsh="ssh -p 10022" localpath soak@localhost:/remotepath 

and again remember that you are actually connecting to soak@10.199.199.191.

share|improve this answer
    
Does it connect to the intermediate server before copying data to remote host? –  shantanuo Sep 28 '11 at 7:27
    
Maybe you should describe your requirements a bit better, especially why you need an intermediate server. Anyway, see my edit. –  SvW Sep 28 '11 at 7:48
add comment

Another way is use SSH Port Forwarding.

First, run the following command on your computer:

$ ssh -N -f -L 2302:10.199.199.191:22 soak@10.10.10.11

This allocated a socket to listen to port 2302 on localhost. Whenever a connection connect to this port, it will be forwarded to 10.199.199.191:22.

So you can copy a folder on 10.199.199.191 to your machine with:

$ scp -r -P 2302 soak@localhost:/path/to/folder /path/to/destination/dir
share|improve this answer
add comment

Also available is ssh's ProxyCommand.

From Undeadly:

Host internal.hostname.tld internal
  User          merdely
  HostName      internal.hostname.tld
  ProxyCommand  ssh merdely@gateway.hostname.tld nc %h %p 2> /dev/null
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.