scp network

drag and drop, but it actually works over a network.

The scp man page is 350 lines long. You need three patterns and you’ll never open FileZilla again.

You needed to copy a file to a server. So you downloaded FileZilla. 15MB. You installed it. You opened it. You entered the hostname, username, password, and port in four separate text fields. You clicked “Quickconnect.” It connected. You navigated to the remote directory in the right panel. You navigated to the local directory in the left panel. You dragged the file from left to right. A transfer window appeared with a progress bar. It finished. You closed FileZilla. It asked if you wanted to save the connection. You clicked “Don’t Save” because you’ll forget you saved it and then wonder why FileZilla has 47 saved connections.

You did all of that to copy one file.

scp copies files over SSH. Same encryption. Same authentication. One command. If you can SSH into a server, you can scp files to it.

Unless you’re running Windows then wtf none of this applies to you. But hey, come to the dark side, go install WSL2 and you can follow along. We’ll wait. Impatiently.

If you’re lazy like me (all sysadmins are!) then click here for the scp cheat sheet.


Copy a file to a remote server

scp file.txt user@server:/remote/path/

That’s it. File copied. Encrypted. Authenticated via your SSH key or password. Done.

The format is: scp LOCAL REMOTE. The remote side is user@host:/path/. If you leave off the path, it goes to the user’s home directory:

scp file.txt user@server:

The trailing colon is important — without it, scp thinks you’re copying to a local file called user@server.


Copy a file FROM a remote server

scp user@server:/remote/path/file.txt ./

Same command, reversed. Remote on the left, local on the right. The file ends up in your current directory.

scp user@server:/var/log/app.log /tmp/

Grab a log file from a server and drop it in /tmp/. For when you need to analyze something locally that lives on a remote machine.


Copy a whole directory

scp -r /local/folder/ user@server:/remote/path/

-r means recursive. The entire directory and everything in it gets copied. This is the “drag a folder” equivalent.

scp -r user@server:/remote/folder/ ./

Download a whole directory from a remote server. Same flag, reversed direction.


Copy between two remote servers

scp user1@server1:/path/file.txt user2@server2:/path/

Copies directly between two remote machines, tunneled through your local machine. You don’t need to download it first and re-upload it. One command, two servers, one transfer.


Use a different SSH port

scp -P 2222 file.txt user@server:/path/

Capital -P (not lowercase like ssh’s -p). Because scp and ssh couldn’t agree on flag casing. That inconsistency has caused approximately eleven billion support tickets.


Preserve timestamps and permissions

scp -p file.txt user@server:/path/

Lowercase -p preserves modification times, access times, and file modes. Without this, the copied file gets the current timestamp and default permissions.


Use SSH key explicitly

scp -i ~/.ssh/mykey file.txt user@server:/path/

If you have multiple SSH keys and need to specify which one to use. Same -i flag as the ssh command.


Compress during transfer

scp -C largefile.sql user@server:/path/

-C enables compression. Useful for large text files (logs, SQL dumps, CSVs) where compression makes a real difference. Less useful for already-compressed files (.tar.gz, .zip) — you’d just waste CPU.


When to use rsync instead

scp copies files. That’s all it does. rsync copies files intelligently — it only transfers what’s changed, can resume interrupted transfers, and preserves everything scp does plus more.

Situation Use this
Copy one file to a server scp — simpler syntax
Copy a few files once scp — no need for rsync’s overhead
Sync a directory regularly rsync — only transfers changes
Resume an interrupted transfer rsync — scp starts over
Large directories with few changes rsync — dramatically faster on repeat runs
Backup with permissions and links rsync — handles symlinks, hardlinks, ACLs

For one-off copies, scp is perfect. For anything recurring or large, rsync is the better tool.


The flags that actually matter

Flag What it does
-r Recursive — copy entire directories.
-P PORT Use a specific SSH port (capital P).
-p Preserve timestamps and permissions.
-C Compress data during transfer.
-i KEY Use a specific SSH key.
-v Verbose — show debug/progress info.
-l LIMIT Limit bandwidth in Kbit/s.
-o OPTION Pass SSH options (e.g., -o StrictHostKeyChecking=no).

“But FileZilla—”

Oh, we’re doing this.

“FileZilla has a nice two-panel interface.” FileZilla’s two-panel interface shows you the local filesystem on the left and the remote filesystem on the right. You navigate both. You drag files between them. It’s a GUI for people who think copying files is a visual activity. scp file.txt server:/path/ doesn’t need a two-panel anything because you already know where the file is and where it’s going.

“WinSCP lets me edit files directly.” WinSCP downloads the file to a temp directory, opens it in an editor, and re-uploads it when you save. That’s three operations pretending to be one. On a real system, you SSH in and edit the file directly. Or use scp to download, edit locally, and scp to upload. At least you know what’s happening.

“I use FTP.” FTP transmits your credentials in cleartext. Your password flies across the network unencrypted for anyone on the same network to read. This has been a known problem since the 1990s. SCP uses SSH encryption. Please stop using FTP. Please.

“Cyberduck supports S3 and SFTP.” Cyberduck is a fine multi-protocol file manager. It’s 80MB. It has a duck icon. You used it to upload one file to an SFTP server. scp file.txt server:/path/ is five words. No duck required.

“I just email files to myself.” You’re emailing files. To yourself. So you can download them on another computer. Rather than copying them directly over the network. This is like mailing a letter to your own house because you couldn’t be bothered to walk to the other room.


scp cheat sheet

You made it. Or you skipped straight here. Either way, no judgment. Copy and paste these. Pin them. Tattoo them on your forearm. Whatever works.

What you’re doing Command
Copy file to server scp file.txt user@server:/path/
Copy file from server scp user@server:/path/file.txt ./
Copy directory scp -r folder/ user@server:/path/
Different SSH port scp -P 2222 file.txt user@server:/path/
Preserve timestamps scp -p file.txt user@server:/path/
With compression scp -C file.txt user@server:/path/
Specific SSH key scp -i ~/.ssh/key file.txt user@server:/path/
Between two servers scp user1@srv1:/file user2@srv2:/path/

The pattern: scp [from] [to] — local or remote on either side. Colon separates host from path. That’s it.

Back to the top, you overachiever.