Transfer files with scp and SFTP
You will often need to move files between your own computer and your server: a website build, a configuration file, or a backup to keep safe. scp and SFTP both do this over the same encrypted SSH connection you already use, so no extra server software is needed.
Before you begin
- Working SSH access to your VPS from your own computer. This guide uses 203.0.113.10 and a user named alex.
- A terminal on your computer. macOS and Linux have one built in. On Windows, use the built-in OpenSSH client in PowerShell or Windows Terminal.
- Your SSH key set up, so you are not typing a password for every transfer.
Step 1: Copy a single file to the server with scp
Run these commands on your own computer, not on the server. scp reads like cp, with a remote address in the middle. The format is source then destination, and the destination is user@address:path. Here we send a local file to the home folder of alex on the server.
scp ./site.zip alex@203.0.113.10:/home/alex/
site.zip 100% 2048KB 1.2MB/s 00:01
A trailing slash on the destination means "put it inside this folder" and keeps the original file name.
Step 2: Copy a folder and copy from the server
Add -r (recursive) to copy a whole folder with everything in it. To pull a file back from the server, swap the order so the remote path comes first.
scp -r ./public-site alex@203.0.113.10:/home/alex/
scp alex@203.0.113.10:/home/alex/backup.tar.gz ./
If your server listens on a different SSH port, such as 2222, add -P with a capital P. Note that scp uses a capital letter for the port, while ssh uses a lowercase -p.
scp -P 2222 ./site.zip alex@203.0.113.10:/home/alex/
Step 3: Browse and transfer interactively with SFTP
SFTP opens an interactive prompt on the server, where you can list folders and move files around. It is handy when you do not yet know the exact paths. Connect first:
sftp alex@203.0.113.10
At the sftp> prompt, these commands do the work:
sftp> pwd # show the remote folder you are in
sftp> ls # list remote files
sftp> lpwd # show the folder on your computer
sftp> lcd ~/Downloads # change the local folder
sftp> put ./site.zip # upload a file to the server
sftp> get backup.tar.gz # download a file from the server
sftp> exit # close the connection
The commands starting with l act on your computer, and the others act on the server. Those two sides are easy to mix up, so check the prompt output when in doubt.
Step 4: Sync a folder with rsync, for repeat transfers
When you copy the same folder again and again, rsync sends only the files that changed. It comes preinstalled on Ubuntu, and on your computer if you use macOS or Linux. The -a flag keeps permissions and timestamps, -v shows progress, and -z compresses data on the way.
rsync -avz ./public-site/ alex@203.0.113.10:/home/alex/public-site/
The trailing slash after public-site/ copies the contents of the folder, not the folder itself.
yes straight away. Confirm the new key with your provider first, then remove the old entry with ssh-keygen -R 203.0.113.10.Troubleshooting
- "Permission denied" when uploading. Your user cannot write to that folder. Upload to your home folder first, then move the file with sudo on the server, or fix ownership as described in the permission guide.
- "Connection refused" or a timeout. The address or port is wrong, or the firewall blocks SSH. Test with
ssh alex@203.0.113.10first. If it fails, the problem is the connection itself, not the file transfer. - "No such file or directory". On your computer, the local path does not exist. Run
pwdandlslocally to confirm the file name. - The transfer is slow. Compression with rsync
-zhelps for text, but not for files that are already compressed, such as zip archives. Large files also take longer over slow home connections, so be patient.
Next steps
Once you can move files confidently, set up a simple way to deploy your site without copying by hand. The guide on deploying with a git push shows how to send changes with a single command.
Something not working? Chat or email our support team and we will help you get unstuck.
Contact support