Copying a Directory with SCP

The Unix command scp (which stands for "secure copy protocol") is a simple tool for uploading or downloading files (or directories) to/from a remote machine. The transfer is done on top of SSH, which is how it maintains its familure options (like for specifying identities and credentials) and ensures a secure connection. It's really helpful to be able to move around files between any machine that supports SSH.

Even if you don't already know how to use the command, scp should be a bit more familiar to you thanks to its similarity to ssh. The biggest differences come with specifying file/directory paths. In this short article we'll be dealing with directories specifically.

Downloading a Directory

In this use-case, we want to use scp to download a directory from a remote server to our local machine. To achieve this, we'll use the -r flag, which tells scp to recursively copy all of the directory's contents to our machine.

Here is an example of using scp to download a directory:

$ scp -r /path/to/local/destination



Uploading a Directory

The same exact concepts as downloading a directory apply here as well. You'll probably notice that the only difference is where we specify the source directory within the actual command.

Here is an example of using scp to upload a folder:

$ scp -r /path/to/local/source 



For more information on the scp command, I'd highly encourage you to check out the docs with man scp. Not only is this the fastest way to learn about the command, but it's a good habit to get in to for any Unix command.