I want to use file transfer via SSH on some scripts. I've read it's possible to tar over ssh. Where should I start reading?
Asked
Active
Viewed 7,891 times
9
-
Why do you bring up tar? – Zoredache Mar 09 '10 at 19:37
-
1tar is the fastest way to copy files over SSH. scp and rsync have a lot of protocol overhead when copying lots of small files. – Justin Mar 09 '10 at 21:12
-
@Justin, of course the assumption with tar is that you will have a reliable connection. If raw performance doesn't matter then it is usually better to stick with the more common and simple solutions like scp/rsync. – Zoredache Mar 09 '10 at 22:04
-
1huh? tar over ssh is no worse then scp or rsync. The only aspect in which rsync is better is that it lets you resume. If the connection isn't reliable it is probably still worth it to try tar over ssh first, and then finish the transfer with rsync. – Justin Mar 09 '10 at 22:10
-
@Justin, that would make a fairly complex script. Perhaps we should start with something just a little more basic. – John Gardeniers Mar 10 '10 at 01:42
4 Answers
23
To do file transfer over ssh you can
- use scp
scp -r /srcdir/ user@remotehost:/destdir/
- use rsync over ssh (see the -e parameter)
rsync -e ssh -a /srcdir/ user@remotehost:/destdir/
- use some tool that transfers data via stdin/out (tar, cpio, etc)
cd /sourcedir; tar -c . | ssh username@remotehost bash 'cd /dstdir; tar -x
- Mount the filesystem via sshfs (if fuse is supported on your system)

Zoredache
- 130,897
- 41
- 276
- 420
-
I regularly use all three; which one I use depends on the circumstances. – reinierpost Mar 11 '10 at 14:22
3
O'Reilly has a book with it all - SSH, The Secure Shell: The Definitive Guide - if you Google for it, there are many references, places to buy it, and view it online.

Kevin K
- 833
- 1
- 6
- 8
-
Gotta love it when you get downvoted and no comments to let you know why. He asked where to start reading - and this is available online and from a bookstore. It is a great reference for ssh. – Kevin K Mar 22 '10 at 18:38
-
I think this is wrong too. Why did you get voted down (twice) given that you actually answered the question and the accepted answer (voted up 15 times so far) is a generic how to copy files over ssh with no reference to where to start reading. I'm gonna vote you up, just to try to remedy the situation. Don't let them get you down man. – Richard Holloway Mar 25 '10 at 23:52
1
Im no expert, but I think http://en.wikipedia.org/wiki/Secure_copy is what you want.

Carl Bergquist
- 181
- 1
- 3
- 7
0
For tar over ssh, you can use the fact the ssh forwards stdin and stdout. So you can do
ssh server 'tar czf - /some/dir/' > tarfile.tar.gz
and have the backup on the local machine.

Dan Andreatta
- 5,454
- 2
- 24
- 14