Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash scp - Secure Copy (remote file copy program)

Using the scp Command

The scp command is used to securely copy files between hosts on a network.


Basic Usage

To copy a file to a remote host, use scp file user@hostname:/path:

Example

scp file.txt [email protected]:/home/user/
[email protected]'s password: 
file.txt

Options

The scp command supports various options to customize its behavior:

  • -r - Recursively copy entire directories
  • -P - Specify the port to connect to on the remote host
  • -i - Specify an identity (private key) file
  • -C - Enable compression
  • -v - Enable verbose mode
  • -l - Limit the bandwidth used by the copy

Option: -r (Recursive Copy)

The -r option allows you to recursively copy entire directories.

Example: Recursive Copy

scp -r /path/to/directory [email protected]:/home/user/
[email protected]'s password: 
1.png 100% 1797KB   2.7MB/s   00:00    
2.png 100% 1873KB   3.2MB/s   00:00    
3.png 100% 1808KB   3.9MB/s   00:00    
...

Option: -P (Port)

The -P option allows you to specify a port to connect to on the remote host.

By default, SCP uses port 22.

Example: Specify Port

scp -P 2222 file.txt [email protected]:/home/user/
[email protected]'s password: 
file.txt

Option: -i (Identity File)

The -i option allows you to specify a private key file for authentication.

This is useful when you have a specific key for a server.

Example: Use Private Key

scp -i /path/to/private_key file.txt [email protected]:/home/user/
file.txt

Option: -C (Compression)

The -C option enables compression, which can speed up file transfer by reducing the amount of data sent over the network.

Example: Enable Compression

scp -C file.txt [email protected]:/home/user/
[email protected]'s password: 
file.txt

Option: -v (Verbose Mode)

The -v option enables verbose mode, providing detailed output about the file transfer process.

This is helpful for debugging.

Example: Verbose Mode

scp -v file.txt [email protected]:/home/user/
Executing: program /usr/bin/ssh host example.com, user user, command scp -v -t /home/user/
file.txt 100% 1234KB 1.2MB/s 00:01
...

Option: -l (Limit Bandwidth)

The -l option allows you to limit the bandwidth used by the copy. This is useful for managing network resources.

Example: Limit Bandwidth

scp -l 100 file.txt [email protected]:/home/user/
[email protected]'s password: 
file.txt

Understanding SCP Output

The output of the scp command will vary depending on the options used. Here are some common elements:

  • Transfer Progress: Shows progress of the file transfer.
  • File Size: The size of the file being transferred.
  • Transfer Speed: The speed at which the file is being transferred.
  • Time Remaining: Estimated time remaining for the transfer to complete.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.