SCP Command Syntax Tutorial

SCP command or Secure Copy command is used to copy files and directories securely between systems via the network. The SCP command is very popular as it provides single, multiple files and directory copy capabilities via the command line interface. As a powerful command, the SCP command provides different syntaxes for different use cases. In this, tutorial we examine the syntax of the scp command.

Upload File From Local To Remote

The scp command can be used to upload local file to the remote file.

scp OPTION  LOCAL_FILE [email protected]_HOST:/REMOTE_PATH
  • OPTIONS are scp command options like compression, encryption type, etc.
  • USER is the username to authenticate the remote host.
  • REMOTE_HOST is the remote host IP address or hostname to upload the file.
  • REMOTE_PATH is the remote system folder path.
  • LOCAL_FILE is the local file path or name

In the following example we copy the file named db.txt into the remote system.

$ scp /home/ismail/db.txt [email protected]:/mnt/db.txt

Download Files From Remote To Local

The scp command can be used to download a remote host file to the local system.

scp OPTION  [email protected]_HOST:/REMOTE_PATH  LOCAL_FILE
  • OPTIONS are scp command options like compression, encryption type, etc.
  • USER is the username to authenticate the remote host.
  • REMOTE_HOST is the remote host IP address or hostname to upload the file.
  • REMOTE_PATH is the remote system folder path.
  • LOCAL_FILE is the local file path or name
$ scp [email protected]:/mnt/db.txt /home/ismail/db.txt

Upload Folder From Local To Remote

The scp command can be also used to upload a folder from the local to the remote system with all files inside.

scp OPTION  LOCAL_FOLDER [email protected]_HOST:/REMOTE_PATH
  • OPTIONS are scp command options like compression, encryption type, etc.
  • USER is the username to authenticate the remote host.
  • REMOTE_HOST is the remote host IP address or hostname to upload the file.
  • REMOTE_PATH is the remote system folder path.
  • LOCAL_FOLDER is the local file path or name
$ scp -r  /home/ismail/db/ [email protected]:/mnt/db/

Download Folder From Remote To Local

The scp command can be also used to download a folder from the remote system to the local system with all files inside.

scp OPTION  [email protected]_HOST:/REMOTE_PATH  LOCAL_FOLDER
  • OPTIONS are scp command options like compression, encryption type, etc.
  • USER is the username to authenticate the remote host.
  • REMOTE_HOST is the remote host IP address or hostname to upload the file.
  • REMOTE_PATH is the remote system folder path.
  • LOCAL_FOLDER is the local file path or name.
$ scp -r [email protected]:/mnt/db/  /home/ismail/db/ 

Copy From Remote Host To Another Remote Host

Interestingly the scp command can be used to copy a file or folder from a remote host to another remote host. As you see we do not use the local host for any upload or download. The syntax of the scp command is like below.

scp OPTION  [email protected]_HOST_A:/REMOTE_PATH  [email protected]_HOST_B:/REMOTE_PATH
  • OPTIONS are scp command options like compression, encryption type, etc.
  • USER is the username to authenticate the remote host.
  • REMOTE_HOST is the remote host IP address or hostname to upload the file.
  • REMOTE_PATH is the remote system folder path.
  • LOCAL_FOLDER is the local file path or name.
$ scp -r [email protected]:/mnt/db/  [email protected]/home/ismail/db/ 
See also  SSH "Error Permission Denied(publickey)" Error and Solution

Leave a Comment