For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /general/ssh_security/How_to_use_SCP.md.

How to Use SCP

SCP (Secure Copy Protocol) is a command-line utility used to securely transfer files between a local and a remote host. It uses SSH (Secure Shell) for the data transfer and provides encryption and authentication.

Basic Syntax of SCP

scp [options] source_file_name username@destination_host:destination_folder

Where:

  • options: the options you can use with SCP:
    • -P: the port number to connect to on the remote host.
    • -r: recursively copies entire directories.
    • -p: preserves the modification times, access times, and modes from the original file.
    • -v: enables verbose mode and shows detailed progress information.
  • source_file_name: the name of the file, including the path, that you want to copy.
  • username: the username on the destination host.
  • destination_host: the IP address or hostname of the destination host.
  • destination_folder: the directory the file is copied to on the destination machine.

Examples

Copy a File to a Remote Server

scp /path/to/source/file.txt username@remotehost:/path/to/destination/

Copy a Directory to a Remote Server

scp -r /path/to/source/directory username@remotehost:/path/to/destination/

Copy a File Using a Specific Port

scp -P 2222 /path/to/source/file.txt username@remotehost:/path/to/destination/
Note

The -P option sets the port on the destination system (the remote host) where the SSH server is running. By default, SCP uses port 22, the standard SSH port. The SSH server on the remote host may be configured to listen on a different port.

More Options

These are basic examples of using SCP. SCP offers many more options for advanced use, such as compression, limiting bandwidth, and specifying private key files.

You can explore them in the SCP manual:

man scp