Home > Linux, Unix Scripting > scp without using scp

scp without using scp

Ever want to use scp to copy from standard input? Maybe you want to avoid writing out a large file before copying, or maybe you don’t have write permissions on the system you’re connected to… Here’s the solution:

tar -c "iwant/" | bzip2 -9 -c | ssh user@host 'cat >/home/user/iwant.tar.bz2'

This works because ssh is executing the command you give it on the target host and piping its stdin to that command’s stdin. Nifty!

Another option is to connect to a remote system and pull down files:

ssh user@host 'cd /home/user/ ; tar -c "iwant/" | bzip2 -9 -c' > iwant.tar.bz2
Advertisement
Categories: Linux, Unix Scripting Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.