g2vbxq
Last Updated: February 25, 2016
·
676
· nerdfunk
Radar normal

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/
Say Thanks
Respond

2 Responses
Add your response

17863
58abfe08f2065deecf69e838eeac3dc0

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

over 1 year ago ·
17874
D42a7264714dee5006b9c99d2567a320

Why not use rsync?

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