keepcalculator

06 Numbers and Powers

SCP Commands Examples for File Transfer

Card No. 06·28343 · Updated · Standard formula, shown below

Estimated transfer time 400.00 min
Time if slower (50% eff.)
800.00 min
Result
Transfer time (min)
12 min
You entered
File size (MB)
500 MB
You entered
You enter
Transfer time (min), File size (MB), Bandwidth (Mbps)
You get
Estimated transfer time, Time if slower (50% eff.)
Rounding
2 dp

SCP (Secure Copy Protocol) is a command-line tool that lets you copy files and directories between your local machine and a remote server over SSH. You use it by typing scp, followed by the source path, the destination path, and the remote server’s address. This article gives you concrete, copy-pasteable examples for the most common tasks, explains the syntax, and points out the pitfalls that trip up most users.

Formula

The calculator above estimates how long an SCP transfer will take. The core formula is:

time (minutes) = (file size in MB × 8) / (bandwidth in Mbps)

Where:

  • File size (MB) – the size of the file or directory you are copying, in megabytes (1 MB = 1,024 KB).
  • Bandwidth (Mbps) – your network connection speed in megabits per second (1 MB = 8 megabits).
  • Time (min) – the estimated transfer time in minutes.

The second output, “Time if slower (50% eff.)�, applies a 50% efficiency factor to account for real-world overhead like TCP handshakes, encryption, and disk I/O. Real transfers rarely hit the theoretical maximum.

Worked Example

Using the default values from the calculator: a 500 MB file over a 10 Mbps connection.

  1. Convert file size to megabits: 500 MB × 8 = 4,000 megabits.
  2. Divide by bandwidth: 4,000 / 10 = 400 minutes.
  3. With 50% efficiency: 4,000 / (10 × 0.5) = 800 minutes.

So the estimate is 400 minutes (about 6.7 hours) at full speed, or 800 minutes (13.3 hours) at half speed. This matches the calculator’s output of 400.00 and 800.00.

SCP Syntax Basics

SCP uses the same authentication as SSH, so you need a username and password (or an SSH key) for the remote server. The general syntax is:

scp [options] source destination

The source and destination can be local paths or remote paths. A remote path is written as user@host:path. If you omit the username, SCP uses your current local username. The colon separates the host from the path – it is mandatory, even if the path is empty (e.g., user@host: means the home directory).

Here are the most common options:

  • -r – recursively copy directories.
  • -P port – specify a non-default SSH port (capital P, unlike ssh’s lowercase -p).
  • -i identity_file – use a specific SSH private key.
  • -C – enable compression, which can speed up transfers of text files.
  • -v – verbose mode, shows debugging messages.
  • -q – quiet mode, suppresses the progress bar and non-error messages.

Copying Files to a Remote Server

To upload a file from your local machine to a remote server, the local path is the source and the remote path is the destination.

scp report.pdf user@192.168.1.10:/home/user/documents/
scp report.pdf user@192.168.1.10:~/backups/

The first example copies report.pdf to the documents folder. The second uses ~ to refer to the user’s home directory. If the destination directory doesn’t exist, SCP will error out – it does not create directories automatically.

To rename the file during upload, just give a new name in the destination:

scp report.pdf user@192.168.1.10:/home/user/documents/final_report.pdf

Copying Files from a Remote Server

To download a file, reverse the order: remote path first, local path second.

scp user@192.168.1.10:/var/log/syslog ./syslog_backup.log

This downloads syslog from the remote server to the current local directory, renaming it to syslog_backup.log. If you want to keep the same name, use a dot for the current directory:

scp user@192.168.1.10:/var/log/syslog .

Copying Directories Recursively

SCP cannot copy a directory unless you use the -r flag. Without it, you’ll get an error like “Not a regular fileâ€�.

scp -r user@192.168.1.10:/home/user/project ./project_backup

This downloads the entire project directory (including all subdirectories and files) into a local folder named project_backup. The same flag works for uploads:

scp -r ./assets user@192.168.1.10:/var/www/html/

Using a Different SSH Port

If the remote server listens on a non-standard port (e.g., 2222), use -P (capital P). This is a common mistake because SSH itself uses lowercase -p.

scp -P 2222 file.txt user@example.com:/home/user/

If you forget the capital P, SCP will treat it as an unknown option and fail.

Common Errors and Troubleshooting

Here are the most frequent problems people run into:

  • Permission denied – wrong username, wrong password, or the SSH key isn’t set up. Check your credentials and that the remote user has write permission on the destination folder.
  • No such file or directory – the source path is wrong, or the destination directory doesn’t exist. Create the directory first with ssh user@host "mkdir -p /path".
  • Connection timed out – the remote host is unreachable, a firewall is blocking port 22, or the SSH service is down. Try ping and ssh separately to isolate the issue.
  • Broken pipe – the connection dropped mid-transfer. Use rsync instead for large or unreliable transfers, as it can resume.
  • Host key verification failed – the remote host’s key changed (or you’re connecting to a new host). Verify the key fingerprint with the server admin before removing the old key from ~/.ssh/known_hosts.

SCP vs. SFTP vs. rsync

SCP is not the only way to transfer files over SSH. Here’s how it compares:

  • SFTP – a full file-transfer protocol that supports interactive browsing, resuming, and file management. SCP is simpler but lacks resume and directory listing.
  • rsync – synchronizes directories, only transfers changed parts of files, and can resume. It’s the preferred tool for large or repeated transfers.
  • SCP – best for one-off copies of a few files, especially when you just want a quick command without setting up anything else.

For a single file, SCP is fine. For a directory with thousands of files or a 10 GB database dump, rsync is more robust. SFTP is better when you need to interactively browse the remote filesystem.

Security and Best Practices

SCP encrypts the data in transit, so it’s safe over untrusted networks. However, a few habits make it even safer:

  • Use SSH keys instead of passwords. Generate a key with ssh-keygen, then copy the public key to the server with ssh-copy-id.
  • Never share your private key. If someone gets it, they can access every server that has the matching public key.
  • Check the host key fingerprint the first time you connect. This prevents man-in-the-middle attacks.
  • Avoid using scp with the root account. Use a regular user and sudo if necessary.
  • For sensitive data, consider adding -C for compression, but note that it increases CPU usage on both ends.

Frequently Asked Questions

How do I copy a file from one remote server to another?

SCP can do this if you run the command from your local machine: scp user1@host1:/path/file user2@host2:/path/. However, the data goes through your local machine, which is slow. Better: SSH into one server and run SCP from there, or use rsync with the -e ssh option.

Why does SCP ask for a password even though I have an SSH key?

Your public key may not be in the remote user’s ~/.ssh/authorized_keys file, or the file permissions are too open (SSH requires it to be 600). Also, the remote server may have password authentication enabled and key auth disabled. Run ssh-copy-id user@host to install your key correctly.

Can I use SCP to copy a file to multiple servers at once?

No, SCP only handles one source and one destination per command. You can write a loop in bash: for host in server1 server2; do scp file user@$host:/path/; done. Or use a tool like pssh or Ansible for parallel copies.

What’s the difference between scp -P and scp -p?

-P (capital) specifies the SSH port, while -p (lowercase) preserves the file’s modification time, access time, and mode. The lowercase -p is the same as the -p flag in cp.

Does SCP work on Windows?

Yes. Windows 10 and 11 include a built-in OpenSSH client, so you can use SCP in PowerShell or Command Prompt. You can also use PuTTY’s pscp.exe or WSL (Windows Subsystem for Linux) for the full Linux experience.

Why is my SCP transfer so slow?

Several factors: network latency, encryption overhead, disk speed, and the default cipher. Try adding -C for compression. If the file is huge, use rsync with --partial to resume. Also check if your ISP or server throttles large transfers.

Related

Formula used
in t | Transfer time (min) | min | 12 | 0 | 1440
in d | File size (MB) | MB | 500 | 0 | 100000
in b | Bandwidth (Mbps) | Mbps | 10 | 0 | 10000
out est | Estimated transfer time | min | d * 8 / b | 2
out actual | Time if slower (50% eff.) | min | d * 8 / (b * 0.5) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →