Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Can scp copy directories recursively?

Currently, I can only copy a single .tar file. But how can I copy directories recursively with scp?
by

2 Answers

akshay1995
Yup, use -r:

scp -rp sourcedirectory user@dest:/path
-r means recursive
-p preserves modification times, access times, and modes from the original file.
Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory
sandhya6gczb
The best way is to use rsync over SSH

rsync -a -essh /source/ user@dest-server:/dest/

rsync -a -essh user@source-server:/source/ /dest/

My favorites options are -Pazvessh --delete :

-a : archive mode (include a lot of default common options, including preserving symlinks)
-z : compress
-v : verbose : show files
-P : show progess as files done/remaining files
-e ssh : do rsync in ssh protocol
--delete : delete files in the destination that are not anymore in the source

Login / Signup to Answer the Question.