Skip to content
BENIBIX Learn

scp, SFTP and rsync

Level 4 · Moving files

Three ways to move files over SSH. scp copies once, SFTP opens a session you can browse, and rsync sends only what changed. When to use each.

Course contentsLesson 7 of 9

After this lesson you can

  • Copy a file with scp
  • Browse and upload with sftp
  • Sync a folder with rsync

13 mincovers 3 glossary entries

Worth reading first: sshd_config and Fail2ban

Which tool to use to move files

Three tools move files over SSH, and all of them use the same keys and the same locked line. scp copies files in one command, like cp across machines. SFTP opens a session where you can list folders, upload and download. rsync compares both sides and sends only what changed. For one file, use scp. For a folder you update often, use rsync.

scp reads like a copy command with an address on one side. scp report.pdf emma@203.0.113.10:/home/emma/ sends one file up. Swap the two sides to bring a file down. Add -r to copy a whole folder.

SFTP is a way to browse files on a server, built into SSH. sftp jack@203.0.113.10 opens a session. Inside it, ls lists files, put uploads one and get downloads one. Many file manager apps speak SFTP too, so you can drag and drop.

rsync is built for folders that change. The first run copies everything. After that, it compares sizes and dates on both sides and sends only the files that changed. A site of 2,000 files with 3 edits sends 3 files.

rsync -av site/ lucy@203.0.113.10:/var/www/site/ is the usual form. -a keeps dates and rights, and -v lists each file. Adding -n first shows what would be sent, with nothing sent at all.

Watch the slash at the end of the source. site/ copies what is inside the folder. site, with no slash, copies the folder itself, so you end up with /var/www/site/site.

A common mistake is rsync --delete without a dry run. It removes files on the far side that are not on yours. With the wrong path, that can be every file on the server. Run it with -n first and read the list.

scp, SFTP and rsync side by side

scpSFTPrsync
Works likeOne copy commandA file browserA sync of two folders
SendsEverything you nameWhat you put or getOnly what changed
Best forOne file, onceLooking around, then a few filesA folder you update often
Dry runNoNoYes, with -n

Which one to pick

  1. 1

    Pick scp

    When you need to send or fetch one file, or one folder, once.

  2. 2

    Pick SFTP

    When you want to look around the server's folders before you choose what to move.

  3. 3

    Pick rsync

    When you send one folder up again and again, like a site after each edit.

scp copies once, SFTP browses, and rsync sends only what changed.

Worked example

Jack's site update

Jack's site has 1,800 files, 400 MB in all. Copying it with scp after each change takes 6 minutes.

He switches to rsync -av site/ web1:/var/www/site/. After he edits 2 pages, rsync sends just those 2 files, and the update takes 3 seconds.

The words for this lesson3

Check yourself

You update the same 2,000-file website folder every day. Which tool fits best?

Finished this lesson?

Marking it complete also marks its 3 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.