Ricard Molins
Ricard Molins

Reputation: 450

Nested scp for remote folder copying

Objective: I am trying to copy a folder and its files from HOST_C to HOST_A. ssh or scp can only be done through HOSTB due to keys.

Infrastructure:

HOST_A<-->HOST_B<-->HOST_C

Current procedure:

ssh to host_B
scp -r from folder at C to folder on B
exit ssh from B
scp -r from  folder on B to folder on A
ssh to host_B again
rm -r folders created

I have made some attempts using ProxyCommand but without luck.

Any suggestions are welcome

Upvotes: 1

Views: 587

Answers (1)

kkeller
kkeller

Reputation: 3247

You could connect from host B to host C with ssh, create a tar archive of the folder to copy and send the output to STDOUT and pipe all this to a second ssh session which connects to host A and unpacks the tar archive received on STDIN.

ssh host_C "cd /somewhere; tar czpf - folder" | ssh host_A "cd /somewhere; tar xzpf -"

Upvotes: 1

Related Questions