Transfer data with SCP

Hello readers! Transferring data to your friends’ machine is not a big deal when using storage devices such as pen drives, CDs, etc. But have you ever intended to migrate files between different systems over a network, to a machine that’s out of your reach, like transferring data between an EC2 instance and your local computer? If yes, then scp is a simple tool to help you out there. Let’s find out then, what is scp and what are its use cases?

What is Secure Copy Protocol (SCP)?

I recently did a post on how SSH works, which elaborate, behind the scene of the protocol. So, as we have SSH for a secure connection, similarly, we have scp for a secure copy. It is a network protocol, based on the BSD and RCP, which supports file transfers between hosts on a network.

scp uses Secure Socket Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data. Therefore, for using , you first need to have an  SSH server.


Normal “cp” (copy) command has the following syntax on *nix platforms. Here, data is copied to a different location in the same system.

Similarly, “scp” follows the same format. But, in this case, data is transferred between 2 different systems. Thus, its syntax is as follows.

SCP with use cases

Transferring files on password-based-authentication

1. From localhost to a remote server.

2. From a remote server to localhost.

3. From one remote server to another, through localhost.

“-3” (option) copies between two remote hosts, transferred through the localhost. Note that, this option disables the progress meter. Without this option, the data is copied directly between two remote hosts, for which, they should be accessible to each other.

Transferring files on key based authentication

1. From localhost to a remote server.

“-i” (option) is used to include the identity file (our private key). Necessary for key based authentication.

2. From a remote server to localhost.

3. From one remote server to another, through localhost.

SCP with different parameters

Parameters either change the behavior or extends the functionality of a command. Let’s see some of the alterations of SCP.

Identity file:   -i

As I have already mentioned this option includes identity file (private key).

Recursive:   -r

This option recursively copies files from the source folder.

Verbose:   -v

This option gives you background information while transferring files as shown below.

Compressed: -C

This option compresses transferring files only in the network, such that when they are received by the destination host, they would return to their original size. Thereby, transfer speed increases while large files are being transferred.

Preserves: -p

This option preserves modification times, access times, and modes from the original file.

If you want to explore more such parameters? Please refer SCP manual page with command.


SCP is a remote file copy program, that’s suit perfectly in cases when you have to transfer data in a single pass. However, FTP is more recommended to transfer multiple files/directories, due to its better session-based control over the connection.

Thanks for reading! And in case of a query, please feel free to write in the comments section below.

An open source enthusiast, who feels passionate about web development!

Leave a Reply

Your email address will not be published. Required fields are marked *