Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Now I can only copy a single tar file,how can I copy directories recursively with scp?

share|improve this question
add comment

4 Answers

up vote 90 down vote accepted

Yup, use -r:

scp -rp sourcedirectory user@dest:/path
share|improve this answer
2  
-p preserves modification times, access times, and modes from the original file. (computerhope.com/unix/scp.htm) –  Steve Jun 16 at 23:06
add comment

While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent.

If you are going to copy something to a remote machine more than once, use rsync. Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general:

$ rsync -av /local/dir server:/remote/dir

will synchronize a local directory with a remote directory. If you run it a second time and the contents of the local directory haven't changed, no data will be transferred - much more efficient than running scp and copying everything every time.

Also, rsync allows you to recover from interrupted transfers very easily, unlike scp.

Finally, modern versions of rsync by default run over ssh, so if scp is already working, rsync should pretty much be a drop-in replacement.

share|improve this answer
5  
"no data will be transferred" except, of course, the data required to determine exactly what has or has not changed. –  thsutton Apr 29 '11 at 5:15
3  
Ha yeah I glossed that over a bit obviously. We're not talking quantum entanglement here. –  Phil Hollenback Apr 29 '11 at 6:01
    
it's so sad that osx, win7 and not even ubuntu uses something like rsync for their GUI yet. –  Cawas Apr 29 '11 at 10:24
1  
+1 Very nice, always used scp but will give it a try. –  Trollhorn Apr 29 '11 at 16:07
1  
dmourati I did answer his question. I told him a better way to do it. –  Phil Hollenback Jan 29 '13 at 21:23
show 2 more comments

That is what the -r option is for. :)

See the scp man page for more info if needed.

share|improve this answer
    
+1 always check the manpage first –  Puddingfox Apr 29 '11 at 18:50
add comment

Recursive Copy Option '-r' (lower case)

scp -r

Which I confuse with the regular local recursive copy option '-R' (upper case)

cp -R
share|improve this answer
1  
I just wanted to point out the difference between cp and scp as -r and -R are not the same. unix.stackexchange.com/questions/18712/… –  Tarun Sep 23 '13 at 14:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.