Technology and General Blog

This tutorial describes how to quickly transfer directories using the Linux scp (Secure Copy Protocol) command.

Inspite of the Linux scp command getting deprecated and changed by SFTP and RSYNC, its use is greatly adopted. Even just after remaining deprecated and changed, possibly SCP is the most popular strategy to transfer data files. Nonetheless, its use isn’t professionally encouraged. Which is why immediately after the scp instructions to down load and add directories, I additional guidelines to do the identical working with the sftp command.

Down load and Upload Directories Employing scp

Uploading or fetching directories with scp is identical to uploading or downloading normal files. The only variation is the -r flag you will need to incorporate for directories to be transferred recursively.

The initially case in point of this tutorial has the subsequent traits you want to change:

  • The username utilized to log in on the distant product is kali.
  • The distant IP handle is 168.1.100.
  • The listing to obtain is named linuxhintdir.

You will need to have to substitute the username, IP tackle, and listing names in accordance to your circumstance.

The example beneath invokes the scp command with the -r (Recursive) flag to specify we want to obtain a directory and not a common file. The scp command and the -r flag are followed by the [email protected]/Host. Then, it is adopted by a colon and the path to the directory you want to down load. Whatever you want to upload or download a listing, the place the place you want to save the listing or standard file is normally specified at the stop of the command. In this circumstance, the linuxhintdir listing will be saved in the /root directory.

The syntax is:

scp -r @:

In my circumstance:

scp -r [email protected]:linuxhintdir/ /root/

Take note: Data files and directories made use of in this tutorial are empty.

As you can see, the file was transferred correctly.

Uploading a directory employing SCP requires a equivalent syntax. The big difference, as I reported previously, is you need to have to type the path exactly where to help save the directory at the conclude of the command.

This is for the reason that the scp command was created to be very similar as attainable to the cp Linux command.

In the adhering to case in point, a directory named localdir found in the current directory is copied to the distant host’s default area, the kali user house listing. By default, if you never specify a patch following the colon, the default route for documents to be copied is the household directory of the user you authenticated.

After invoking SCP, incorporate the -r flag to specify you are transferring a listing and not a regular file. Then, specify the listing you want to ship adopted by <[email protected]: as proven in the illustration underneath:

scp -r localdir [email protected]:

As you can see in the next screenshot taken from the distant host, the directory was copied recursively:

Downloading and Uploading Normal Files Utilizing scp

As explained earlier, downloading and uploading typical files is pretty much the exact as with directories besides for the absence of the -r flag, which is not essential.

To add a file, use the subsequent syntax:

scp @:

For that reason, to add a file named linuxhintfile to the remote default directory, recognised as the kali user household directory, I operate the pursuing command:

scp linuxhintfile [email protected]:

To down load a file, the syntax is the adhering to:

scp @:

The subsequent example demonstrates how to down load a file named linuxhintfile, to retailer in the household listing of the remote person named kali, and conserve it in the area user’s Downloads directory.

scp [email protected]:linuxhintfile ~/Downloads

As shown, the file was transferred accurately.

Download and Upload Information and Directories Employing sftp

Downloading and uploading information and directories working with SFTP can be basic as with SCP.

The adhering to system exhibits how to down load a file positioned in the distant subdirectory named dir. The file will be domestically saved in the /tmp/linuxhint2 listing.

sftp [email protected]:dir/file /tmp/linuxhint2

Downloading directories is the same course of action. The instance under reveals how to obtain the dir listing to the current site specified with a dot:

sftp -r [email protected]:dir/ .

Uploading directories isn’t so uncomplicated as with SCP and the syntax improvements. This is since you want to join to the SFTP server to and operate the set command to upload the file.

In the case in point below, the file named linuxhintfile is uploaded to the dir subdirectory on the distant host:

sftp [email protected]:dir

Uploading directories also necessitates applying the -r flag for recursive transference. However, when uploading, the -r flag must be placed after the place command, as shown in the case in point underneath in which the directory linuxhintdir is uploaded to the remote subdirectory named dir.

sftp [email protected]:dir

As you can see, the listing was uploaded successfully. That’s how you can obtain and upload files and directories in Linux employing scp commands or the far more recommended sftp commands.


As you can see, copying directories in Linux remotely applying the scp command is fairly uncomplicated. The scp command is considered the most user-welcoming method to transfer files concerning equipment, and it was after deemed secure as its title, Protected Duplicate Protocol, indicates. At this time, the scp command is obsolete due to vulnerabilities and should not replace safer alternatives like SFTP and RSYNC. The sftp command can also be utilized in interactive mode, which wasn’t defined in this tutorial, but you can go through it at All units supporting SCP need to guidance SFTP, so availability ought to not be a difficulty. In long term tutorials, the RSYNC alternative will be discussed, so maintain subsequent this site for further Linux recommendations and tutorials.

Thank you for looking at this SCP tutorial, I hope it was valuable to you.

Leave a Reply

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