3

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?

shantanuo
  • 3,579
  • 8
  • 49
  • 66

4 Answers4

6

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.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • Does it connect to the intermediate server before copying data to remote host? – shantanuo Sep 28 '11 at 07:27
  • Maybe you should describe your requirements a bit better, especially why you need an intermediate server. Anyway, see my edit. – Sven Sep 28 '11 at 07:48
2

You could pipe tar.

eg.

ssh soak@10.10.10.11 "ssh soak@10.199.199.191 'tar cf - test_directory'" | tar xf -
pyhimys
  • 1,287
  • 10
  • 10
2

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
quanta
  • 51,413
  • 19
  • 159
  • 217
0

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
AFresh1
  • 166
  • 3