How to Use SCP Command to Transfer Files/Folders in Linux

How to Use SCP Command to Transfer Files Folders in Linux
How to Use SCP Command to Transfer Files Folders in Linux

Use SCP Command to Transfer Files/Folders in Linux

SCP command is used to copy files between to systems in a secure way. SCP stands for Secure Copy which copies files or directories securely. By using SCP command you can copy or transfer files from the remote system to the remote system or remote system to the local system. SCP command encrypts data and passwords sent to another system for security. In this tutorial, you are going to learn how to use SCP command to transfer files/folders in Linux.

Prerequisites

Before you start to learn how to use SCP command to transfer files/folders in Linux. You must have the non-root user account on your system with sudo privileges.

Basic Syntax For SCP Command

Following is the basic syntax for SCP command.

scp [OPTION] [[email protected]]SOURCE_HOST:filename1 [[email protected]]DESTINATION_HOST:filename2

Where,

[[email protected]]SOURCE_HOST:filename1 = Source File Name
[[email protected]]DESTINATION_HOST:filename2 = Destination File Name
OPTIONS = SCP options like recursive copy, SSH port etc.

  • -r option used for Recursively coping directories.
  • -P used for Remote host ssh port.
  • -C option used for compressing data before sending.
  • -c option used for selecting cipher to transfer data.

Using SCP Command

Following are the examples for SCP Command.

Provide Estimated Time And Connection Speed

SCP command also provides estimated time and connection speed for transferring file. You can achieve this by using -p option with SCP command.

scp -p Filename.zip [email protected]:.

The output should look like:

[email protected]'s password:
Filename.zip 100% 9800KB 178KB/s 00:55

Use another cipher to encrypt files

By default, SCP uses cipher AES-128 to encrypt files. You can use another cipher using the option -c with SCP command.

Following is an example using.3DES Algorithm

scp -c Filename.zip [email protected]:.

Copy files to the remote system from a local system using SCP command.

You can copy files to the remote system from a local system using the following command.

scp filename.zip [email protected]:/path/to/directory

In above example, filename.zip will be copied to remote hosts given directory.

By default it will copy a file to the directory with its default name, If you want to specify a name for the file then you can do so by using the following command.

scp filename.zip [email protected]:/path/to/directory/newfile.zip

In below example, The file filename.zip will be copied to remote hosts directory with a new name as newfile.zip.

You can copy directory instead of a file, using option -r stands for a recursive copy. In below example final_code directory will be copied to remote systems directory.

scp -r /path/to/final_code rem[email protected]:/path/to/directory

Copy a remote file to local system using SCP command

You can also copy a file from the remote system to the local system using SCP command in which you should specify the source and destination file name.

In below example, the file filename.zip on remote system will be copied to local systems directory.

scp [email protected]:/path/to/remote/filename.zip /path/to/local/directory

Copy files between to remote systems using SCP command

You can copy files between two remote systems using the path to source and destination directory on each system.

In below example, filename.zip file from system 139.168.x.x to the specified directory of 45.89.x.x system.

scp [email protected]:/files/filename.zip [email protected]:/path/to/directory/

You will be also prompted for passwords of both systems for transferring data from one system to another.

If you want to copy directory then you can use the following example command using option -r.

scp -r [email protected]:/files/filename.zip [email protected]:/path/to/directory/

Conclusion

You have successfully learned how to use SCP command to transfer files/folders in Linux. If you have any queries regarding this then please don’t forget to comment below.