Last Updated: February 25, 2016
·
1.095K
· nerdfunk

Quickly pipe a directory over ssh

Sometimes I find it useful to quickly pipe directory contents over ssh.
Since scp only allows to copy single files, a good solution is to simply tar a directory up, and pipe the resulting archive to ssh.

$ tar zcf - some_dir | ssh user@host 'tar zxf -'

To extract to somewhere else than ~ you can specify the path with -C:

$ tar zcf - some_dir | ssh user@host 'tar zxf - -C /tmp/'

Note, that the directory you are trying to extract to must exist on the server.

To copy from remote to local, simply do the inverse:

$ ssh user@host 'tar zcf - some_dir' | tar zxf -  

or with -C

$ ssh user@host 'tar zcf - some_dir' | tar zxf -  -C /tmp/

2 Responses
Add your response

You say "scp only allows single files".. I regularly use wildcards & -r (recursive) with scp, without issue.

over 1 year ago ·

Why not use rsync?

rsync -az --progress /local/dir user@host:/target/path
over 1 year ago ·