Skip to content
VDS · Machine access

scp and rsync: copying files

Two commands for transferring files between your computer and a server: when scp is enough, what rsync is useful for, and how not to overwrite someone else's directory with a trailing slash.

Updated August 23, 2026

A graphical client is handy for a one-off edit, but deployments and backups are easier to do with a single command.

scp: one-off copying

The syntax is the same as cp, only with a machine address:

scp dump.sql root@203.0.113.10:/root/
scp root@203.0.113.10:/var/log/nginx/error.log ./
scp -r ./site root@203.0.113.10:/var/www/

The first command sends a file, the second pulls one back, the third copies a whole directory (-r).

If SSH runs on a different port, specify it with a capital -P:

scp -P 2222 dump.sql root@203.0.113.10:/root/

With a ~/.ssh/config file, the commands get shorter: scp dump.sql vds:/root/.

rsync: synchronization

rsync transfers only the differences, can resume an interrupted transfer and show progress. For repeat deployments it's many times faster.

rsync -avz --progress ./site/ root@203.0.113.10:/var/www/example.com/
FlagWhat it does
-aPreserves permissions, timestamps, links
-vPrints the list of files
-zCompresses the stream
--progressShows transfer progress
--deleteDeletes on the machine whatever you don't have
--excludeSkips anything unnecessary

An example of a clean deployment:

rsync -avz --delete \
  --exclude '.git' --exclude 'node_modules' --exclude '.env' \
  ./site/ vds:/var/www/example.com/

Pull a copy from the machine to your side:

rsync -avz vds:/root/backup-2026-08-23.tar.gz ./backups/

A trailing slash on the source means “the contents of the directory”. ./site/ puts the files inside the target, ./site creates a site subdirectory inside the target. Half of all “missing” deployments are because of it.

Be careful with --delete

The --delete flag makes the directory on the machine an exact copy of yours: anything extra is deleted without asking. Do a dry run first:

rsync -avzn --delete ./site/ vds:/var/www/example.com/

The -n flag only shows what would happen. Once you're sure, drop the n.

Speed

Disk speed is capped per tier: writes at 60 MB/s per core (no less than 60 and no more than 400), reads twice that, and a burst three times the cap holds for 30 seconds. Network bandwidth is up to 500 Mbit/s. On VDS-1, uploading a large archive will hit the write limit, and that's expected, not a failure. To check what's happening:

df -h
iostat -x 2

Common mistakes

SymptomCause
Permission deniedYou're writing to a directory that isn't your user's — log in as root or change the owner
No such file or directoryThe directory doesn't exist on the machine and scp won't create it: run mkdir -p beforehand
Files landed one level higherA missing or extra trailing slash in the path
rsync: command not foundInstall the package on both sides: apt install -y rsync
The site returns 403 after deploymentThe owner isn't set: chown -R www-data:www-data /var/www/example.com

If you prefer a graphical client, see transferring files over SFTP.