Copying Files with SCP

SCP (Secure Copy Protocol) is a command-line tool for securely transferring files between computers over SSH.

The basic SCP command syntax looks like this:

Basic Commands

scp [options] file_name user@destination_host:destination_directory

This command copies the specified file (file_name) to a specific directory (destination_directory) on the destination host (destination_host) using the specified user account (user).

Example:

scp -v file.pdf root@10.10.10.2:.

Recursive Copy of Directories

scp -r /root/documents root@10.10.10.2:.

Using SCP to Download Files

SCP (Secure Copy Protocol) is also used to securely copy files between a local and a remote machine over SSH.

Downloading a File from a Remote Server

Use the command:

scp username@remote_host:/path/to/remote/file /path/to/local/folder

Example:

scp user@example.com:/home/user/file.txt ~/Downloads/

Where:

  • user — the username on the remote server.
  • example.com — the address of the remote server.
  • /home/user/file.txt — the file path on the server.
  • ~/Downloads/ — the local folder path where the file will be saved.

Downloading a Folder from a Remote Server

To download a directory, use the -r option:

scp -r username@remote_host:/path/to/remote/folder /path/to/local/folder

Example:

scp -r user@example.com:/home/user/documents ~/Downloads/

Additional Options

  • -P <port> — specify a non-standard SSH port.
  • -i <key_file> — specify a private SSH key for authentication.
  • -C — enable data compression during transfer.

Example with a custom port and key:

scp -P 2222 -i ~/.ssh/id_rsa user@example.com:/home/user/file.txt ~/Downloads/

SCP is convenient for quick, encrypted file transfers, but for large amounts of data, it’s better to use rsync.


🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email