Copy From Local To Remote with SCP Command

The scp command can copy files securely from the local system to the remote system via the network. During the copy from local to remote the transmitted data is encrypted which makes this copy secure. Also, specified local directories or files can be copied recursively to the remote system. In this tutorial, we will examine different ways to copy from local to the remote by using scp command.

Copy From Local To Remote scp Syntax

The scp uses the following syntax in order to copy local file or folders into the remote system.

scp OPTION LOCAL REMOTE
  • OPTION is used to specify different options to the scp command. This is optional.
  • LOCAL is the local files or directories we want to copy to the REMOTE. This is required.
  • REMOTE is the remote files or directories. This is required.

Copy From Local To Remote Single File

The most basic usage scenario to copy from local to the remote with the scp command is copying a single file. In the following example, we will copy the file named myfile.txt into the remote system with the IP address 192.168.1.10.

scp myfile.txt 192.168.1.10:/home/ismail/myfile.txt

Alternatively, we can specify the remote system with a hostname or domain name like below. In order to use the hostname or domain name, it should be resolved into the IP address of the remote system properly.

scp myfile.txt srv1.linuxtect.com:/home/ismail/myfile.txt

Copy From Local To Remote Directory Recursively

In most of the cases the scp command is used to copy more than single file or directory. Multiple files and directories can be copied from local to the remote recursively. The -r option is specified to the scp command for recursive copy. In the following example we will copy the /home/ismail/ directory and all its contents to the remote server 192.168.1.10.

scp -r /home/ismail/ 192.168.1.10:/mnt/backup/

Alternatively, we can specify the remote system with a hostname or domain name like below. In order to use the hostname or domain name, it should be resolved into the IP address of the remote system properly.

scp -r /home/ismail/ srv1.linuxtect.com:/mnt/backup/

Copy From Local To Remote Specific File Extensions

The scp command is very handy for the copy operation. We can specify the extension of the files we want to copy from local to remote. Simply the * asterisk or glob operation can be used to specify the name part and an extension can be added. In the following example, we will only copy text files with the “*.txt” extension.

scp -r /home/ismail/*.txt 192.168.1.10:/mnt/backup/
READ  Linux ls Command Sort Files By Size

Leave a Comment