How to Transfer Files To and From a VPS (SCP, SFTP & rsync)

Whether you're uploading a website, downloading a backup, or syncing an entire directory, SSH provides three reliable ways to move files to and from your VPS: scp, sftp, and rsync. This guide covers when to use each.

Prerequisites

  • SSH access to your VPS
  • An SSH client on your local machine (built into Windows/macOS/Linux)

Method 1 — SCP (Simple Copy, Best for One-Off Transfers)

Upload a single file to the VPS:

scp file.txt deploy@YOUR_SERVER_IP:/home/deploy/

Download a file from the VPS:

scp deploy@YOUR_SERVER_IP:/home/deploy/backup.sql .

Copy an entire directory recursively:

scp -r ./site deploy@YOUR_SERVER_IP:/var/www/

Specify a custom SSH port:

scp -P 2222 file.txt deploy@YOUR_SERVER_IP:/home/deploy/

Method 2 — SFTP (Interactive, Browsing-Friendly)

sftp deploy@YOUR_SERVER_IP

Common SFTP commands once connected:

ls          # list remote files
lls         # list local files
cd path     # change remote directory
lcd path    # change local directory
put file    # upload a file
get file    # download a file
put -r dir  # upload a directory
exit        # close the session

For a graphical experience, SFTP is also supported by FileZilla, WinSCP, and most modern code editors (VS Code Remote-SSH extension).

Method 3 — rsync (Best for Syncing & Large/Repeated Transfers)

Unlike scp, rsync only transfers what has changed — making it far faster for repeated syncs or large directories.

rsync -avz --progress ./site/ deploy@YOUR_SERVER_IP:/var/www/site/

-a preserves permissions and timestamps, -v is verbose, -z compresses during transfer.

Download from VPS to local:

rsync -avz deploy@YOUR_SERVER_IP:/var/www/site/ ./local-copy/

Mirror exactly, deleting local files that no longer exist remotely (use with caution):

rsync -avz --delete deploy@YOUR_SERVER_IP:/var/www/site/ ./local-copy/

Using a custom SSH port with rsync:

rsync -avz -e "ssh -p 2222" ./site/ deploy@YOUR_SERVER_IP:/var/www/site/

Which Method Should You Use?

ScenarioBest Tool
Copying one file quicklyscp
Browsing remote files interactivelysftp (or a GUI client)
Syncing a large directory repeatedlyrsync
Automated backup scriptsrsync

Common Errors

Permission denied — verify the destination directory is writable by your user, or use sudo-aware paths carefully (SCP/rsync run as the connecting user, not root, by default).

Connection refused — confirm the SSH port matches (use -P for scp, -p inside the -e flag for rsync).

Best Practices

  • Use rsync for anything beyond a single small file
  • Never disable strict host key checking permanently just to silence a warning — verify the fingerprint first
  • Use SSH keys, not passwords, for automated/scripted transfers

FAQ

Is SFTP the same as FTP?
No — SFTP runs entirely over the encrypted SSH protocol, while plain FTP is unencrypted and not recommended for transferring credentials or sensitive data.

Continue Reading

Browse more articles in Linux Server Administration.

  • scp, sftp, rsync, file transfer, ssh
  • 0 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

How to Update and Upgrade Your Ubuntu or Debian VPS

Keeping your VPS updated is one of the most important and simplest maintenance tasks — it...

How to Enable and Configure Swap on a Linux VPS (Ubuntu & Debian)

Swap is disk space Linux can use as overflow memory when physical RAM is exhausted. It won't make...

How to Manage Services with systemd and systemctl

systemd is the service manager used by Ubuntu, Debian, and most modern Linux distributions to...

How to Read and Analyze Linux Logs with journalctl

On modern Ubuntu and Debian systems, journalctl is the central tool for viewing system and...

How to Schedule Tasks with Cron on a Linux VPS

Cron is the standard Linux job scheduler, used to automate recurring tasks like backups, log...