What is scp? - Knowledge Base - Pair Networks (2024)

Shared

VPS

Dedicated

WP Enthusiast

WP Professional

WP Professional Plus

What is scp?

scp stands for Secure Copy Protocol. It is a secure file transfer protocol that copies files to and from hosts. It uses Secure Shell (SSH) to keep the files protected while in transit.

scp is a command line utility, meaning you will have to use Terminal (Mac) or Command Prompt (Windows).

Why use scp?

Since scp uses SSH, the transferred data will be encrypted. This keeps your information from being compromised during transit.

scp is operated by writing single commands into the command line, making it a good option for repeatedly updated files.

Basic Syntax

The basic syntax of scp looks like this:

$ scp source_file_path username@hostname:destination_file_path

And if you were moving file.txt in folder1 on host1 to localFolder in your localDocuments:

$ scp folder1/file.txt username@host1:Documents/localFolder

Common scp Commands


-B|Enables batch mode, which keeps scp from asking for passwords.


-C|Enables compression. See common use cases.

Do not confuse with -c, which is lowercase and has an alternate meaning.


-l|Limits the bandwidth used. Uses Kbit/s.


-p|Maintains the access times, modification times, and modes of the original file.


-q|Enables quiet mode, which prevents the progress meter, diagnostic messages, and warning messages from appearing.


-r|Used to copy entire directories recursively. See common use cases.


-v|Enables verbose mode. See common use cases .

Common Use Cases

Verbose Output

This is used when a program is giving you problems, such as failing or not completing a request.

The verbose output shows you all the processes going on in the background, thus allowing you to sift through and find where the program is running into a problem.

Add -v when you want to see the verbose output.

$ scp -v/file.txt [emailprotected]:/root/file2.txt

Transfer Multiple Files

You can transfer multiple files by putting file names at the beginning:

$ scp file1.txt file2.txt username@remotehost:/destination/file/path/

Or putting them at the end:

$ scp username@host:/destination/file/path/\{file1.txt,file2.txt} .$ scp [emailprotected]:~/\{file1.txt,file2.txt} .

Copy Entire Directory

The -r stands for “recursive.” This is used when you need the application to work as a whole and run through processes a number of times.

This is needed when copying an entire directory.

Add -vif you would like to see the processes working in the background.

Local to remote:

$ scp -r /local/file/path username@host:/remote/file/path

Remote to local:

$ scp -r username@host:/remote/file/path /local/file/path

Copy Files Across Two Remote Hosts

You can copy files to two remote hosts.

$ scp username1@host1:/remote/file/path/file1.txt username2@host2:/remote/file/path/

Speed Up the Transfer with Compression

The -vrC stand for -v, -r, and -C. This option can speed up transfer time and save bandwidth. Use -Cto enable compression. The files will be decompressed when they reach their destination.

$ scp -vrC username@host:/destination/file/path

Preserve File Attributes

You can preserve the file’s access times, modification times, and modes by using -p.

$ scp -C -p ~/file.txt username@host:/file/path/file.txt
What is scp? - Knowledge Base - Pair Networks (2024)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6249

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.