January 18, 2021



SCP copy directories

SCP copy directories

SCP copy directories

SCP copy directories – How to use.
Previously i posted an article on how to use SCP to download or upload files. You can find that here http://soltveit.org/linux-scp-to-download-or-upload-files/

That only goes for files, and not directories. How you copy whole directories is very similar. You just need and extra parameter to the SCP command. Add the -rp parameter to your SCP command.

SCP Copy directories usage:
scp -rp sourcedirectory user@dest:/path

What the parameters means:
-r recursive
-p preserves modification times, access times, and modes from the original file

SCP Copy directories example #1
Lets copy a directory from our local system to a remote system.
scp -rp photos john@

The above command copy the local directory photos and uploads it to a remote system inside Johns mybackup folder. Existing files and folders will be overwritten with this method. Only if they have the same folder and filenames of course.

SCP Copy directories example #2
In this example we will download a folder from a remote system to our local system. Using the SCP command to download the entire folder and sub-folders if there are any.
scp -rp john@ mybackup

This command will download Johns photo folder and save it inside our mybackup folder on our local system.

If you want to read more about the SCP command, check out the Linux man page about SCP here http://linux.die.net/man/1/scp

One last tip

There is another parameter you can use to save time and bandwidth.
-C Compress on the fly. Note this is a capital C.
This will compress the files on the fly, send the files compressed and decompress them on the remote system. For large data amount I would give it a try to see how it perform compared to a uncompressed data transfer.

Thats all I had for copying directories with SCP.

Happy copying!