Pages

Saturday, May 25, 2024

The Ultimate SCP Command Guide: Pushing and Pulling Files with Ease

The Ultimate SCP Command Guide: Pushing and Pulling Files with Ease

The scp (secure copy) command is used to securely transfer files between hosts on a network. It uses SSH for data transfer and provides the same authentication and security as SSH. Below are explanations and examples for using scp to "pull" files (download) and "push" files (upload).

SCP Pull Command (Download Files)

Syntax:

scp [options] username@source_host:file_path destination_folder

Example: Suppose you want to download a file named example.txt from a remote server 192.168.1.5 where your username is john. You want to save this file to the local directory /home/john/documents.

scp john@192.168.1.5:/path/to/example.txt /home/john/documents

In this command:

  • john@192.168.1.5: specifies the username and the host from which the file will be downloaded.
  • /path/to/example.txt is the full path to the file on the remote host.
  • /home/john/documents is the local directory where the file will be saved.

SCP Push Command (Upload Files)

Syntax:

scp [options] file_path username@destination_host:destination_folder

Example: If you want to upload a file named report.pdf from your local directory to a remote server 192.168.1.10 where your username is john, and you want to place this file in the remote directory /home/john/reports.

scp /path/to/local/report.pdf john@192.168.1.10:/home/john/reports

In this command:

  • /path/to/local/report.pdf is the path to the file on your local machine.
  • john@192.168.1.10: specifies the username and the host to which the file will be uploaded.
  • /home/john/reports is the directory on the remote host where the file will be placed.

Useful Options

  • -r: Recursively copy entire directories.
  • -p: Preserves modification times, access times, and modes from the original file.
  • -q: Use this option to operate in quiet mode, which suppresses the progress meter as well as warning and diagnostic messages.
  • -C: Enables compression. This can speed up transfers, particularly over slower connections.

These commands demonstrate basic scp usage for transferring files between local and remote machines securely.

No comments:

Post a Comment