copy from host1 to host2, through your host

ssh root@host1 "cd /somedir/tocopy/ && tar -cf - ." | ssh root@host2 "cd /samedir/tocopyto/ && tar -xf -"
Good if only you have access to host1 and host2, but they have no access to your host (so ncat won't work) and they have no direct access to each other.

By: peshay
2010-04-16 06:48:47

1 Alternatives + Submit Alt

What Others Think

i like this, but it takes the content of the directory you copy from and puts it where you specify, i'm not quite sure how you would do a certain file without takign the whole directory.
alf · 597 weeks and 3 days ago
for a certain file you could do ssh root@host1 "tar -cf - certainfile" | ssh root@host2 "tar -xf -" for text file you also may use something like ssh root@host1 "cat certainfile.txt" | ssh root@host2 "cat >> certainfile.txt" but I didn't tried it yet
peshay · 597 weeks and 3 days ago
There's no reason to use tar at all if it's just a single file -- you could do ssh root@host1 cat filename | ssh root@host2 cat >filename This method means typing the filename twice, though. But it's worth noting that if host1 can log in to host2 directly (and it seems you need to have SSH keys set up so host2 won't ask for a password from host1) you can do scp root@host1:filename root@host2:
tremby · 597 weeks and 3 days ago
That first example should have had host2's commands in quotes otherwise it'll redirect to a file on your local machine. So ssh root@host1 cat filename | ssh root@host2 "cat >filename" No quotes are needed for command for host1 in this case.
tremby · 597 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: