The scp
command is used to copy files and directories over the network in a secure way. As a command files can be copied via the command-line interface. The scp name comes from Secure Copy
. The scp command is provided by most of the Linux distributions can be used to copy from the remote server to the local system. The remote server can be a Linux system or a Windows or just an SSH server with scp feature.
scp From Remote to Local Syntax
The scp command has the following syntax in order to copy files from remote to the local.
scp USER@REMOTE:REMOTE_PATH LOCAL_PATH
- USER is the remote system user.
- REMOTE is the remote system IP address or hostname.
- REMOTE_PATH is the remote system file or directory location.
- LOCAL_PATH is the local system path where the REMOTE_PATH files or folders will be copied to.
Copy File From Remote To Local
In the following example, we copy a single file from the remote to the local. The remote system IP address is 192.168.1.10 and the remote file path is /home/ismail/db.txt. The local path is /home/ahmet/db.txt.
$ scp [email protected]:/home/ismail/db.txt /home/ahmet/db.txt
Copy Multiple Files From Remote To Local
The scp command can be also used to copy multiple remote files to the local system. In the following example, we use the glob operator in order to select multiple files for the copy operation. We copy all *.txt
files from remote to the local.
$ scp [email protected]:/home/ismail/*.txt /home/ahmet/
Copy Directory From Remote To Local Recursively
The scp command can be also used to copy remote directories to the local system. By default, the scp command copies only the specified directory and not its contents. But recursive option -r
can be used to copy remote system directories to the local in a recursive manner.
$ scp -r [email protected]:/home/ismail/ /home/ahmet/
Specify Different Scp Port
The scp command and protocol is an extension to the SSH protocol and service. So scp command uses the SSH services for data transfer. The default SSH port number 22 is used for transmission but we can change the port number. The -p
option is used to specify the remote system port number.
$ scp -r -p 2222 [email protected]:/home/ismail/ /home/ahmet/