SCP Remote to Local

SCP is the abbreviation of the Secure Copy, which uses the ssh service to securely transfer information between two machines. When the information is copied from the local machine to the remote machine using the SCP, unauthorized users cannot access the information. 

This post will demonstrate the methods to copy files and directories from remote to local using SCP:

Prerequisites: Install and Configure SSH 

The prerequisite of using the SCP to copy files from the remote local machine is that the SSH package should be installed on both the remote and the local machine. For installing the SSH on both machines, you can take help from the mentioned guide

How to Use the SCP for Copying Files From Remote to Local?

The SCP can copy files from the remote machine to the local machine. The syntax of using the SCP command for copying the files either from local to remote or vice-versa is:

Syntax

$ scp [OPTION] [user@SRC_HOST:]file1 [user@DEST_HOST:]file2

The explanation of the above general syntax of SCP is:

  • OPTION: You can use different options which are provided below the table.
  • user@SRC_HOST: Define the user name with the local machine’s hostname.
  • file1: Type the name of the file which is supposed to copy.
  • user@DEST_HOST: Define the user name with the remote machine’s hostname.
  • file2: Type the name of the file or directory where the copied content is supposed to be pasted.

Note: In the general syntax of the SCP command, colon (:) is used, which is necessary to differentiate between the local and remote machine.

The different options which can be used with the SCP command are

-PIt defines the port number
-rIt defines the files that are to be copied recursively 
-CIt will compress the data before sending it to the destination folder
-pIt will preserve the file modifications

Now, we will copy the “MyPadminFile” from the remote machine to our local machine using the SCP command. To copy the file, we will use the command:

$ scp  [email protected]:/home/padmin/MyPadminFile /home/itslinux/Documents/

If the password protects the remote machine, it may ask for it for authentication purposes. A file “MyPadminFile” has been copied from remote to local, which can be confirmed by displaying the contents of the “Documents” directory of the local machine:

$ ls Documents

The file has been successfully copied from the remote to local using the SCP command. 

How to Use the SCP for Copying Directory From Remote to Local?

We can also use the SCP command to copy the entire directory from the remote to the local machine. For example, we will copy the “padman_directory” from remote to local using the command:

$ scp -r [email protected]:/home/padmin/padman_directory /home/itslinux/Documents/

List down the contents of the “Documents” Directory to confirm the execution of the above command:

$ ls /home/itslinux/Documents/

The directory “padman_directory” has been copied from the remote to local using the SCP.

How to Use the SCP for Copying Multiple Files From Remote to Local?

We can also use the SCP for copying multiple files from the remote to the local machine. For example, we copy MyPadminFile1, MyPadminFile2, and MyPadminFile3 files that are present in the “padmin_directory” from remote to local using the command:

$ scp [email protected]:/home/padmin/padman_directory /home/itslinux/Documents/

After the execution of the command all the files are copied to the “Documents” directory of the local machine. 

Copy Multiple Files From Remote to Local Server

We can also copy the files MyPadminFile4, MyPadminFile5, and MyPadminFile6 from remote to local using the command:

$ scp [email protected]:/home/padmin/{MyPadminFile4,MyPadminFile5,MyPadminFile6} /home/itslinux/Documents/

Now, we can see that it copies the file by making the connection with the remote machine again and again. 

Verify Directory Contents

To verify the execution of the above two commands; we will list down the directory contents of “Documents”:

$ ls Documents

All the files are successfully copied from the remote to the local machine. 

Conclusion

To copy the files from the remote to the local machine using the SCP, run the command “scp [user@SRC_HOST:]file1 hostmachine_loation”. In this blog, the method of copying files from the remote to a local machine has been explained in detail with the help of examples. Also, the method of copying multiple files in a single command has been explored using the SCP command.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×