Linux VPS

Transfer files to a Linux server with scp and sftp

Copy files and folders between your computer and a server with scp, browse and transfer interactively with sftp, use custom ports and keys, and pick the right tool.

BeginnerLinux VPS2 min read

Need to upload a backup or download a log? scp and sftp transfer files over SSH, so they work wherever you can log in, with no FTP server to install and everything encrypted. They are built into Linux, macOS and Windows 10/11.

Before you start

  • SSH access to the server (password or key).
  • The SSH port if it is not 22.

Copy files with scp

The syntax is scp source destination, where a remote path is written user@host:path.

Upload a file:

scp backup.tar.gz root@203.0.113.10:/root/

Download a file:

scp root@203.0.113.10:/var/log/nginx/error.log .

Copy a whole folder with -r:

scp -r ./site root@203.0.113.10:/var/www/
OptionDoes
-P 2222Custom SSH port (capital P for scp)
-i ~/.ssh/keyUse a specific private key
-CCompress during transfer
-pPreserve modification times and modes
-l 8000Limit bandwidth (Kbit/s)

If you have a Host alias in ~/.ssh/config, use it directly: scp file myvps:/root/.

Work interactively with sftp

sftp -P 22 root@203.0.113.10

(For sftp the port option is also -P.) You get an sftp> prompt with familiar commands:

CommandDoes
ls / llsList remote / local files
cd / lcdChange remote / local directory
put fileUpload
get fileDownload
put -r folder / get -r folderRecursive transfer
reput / regetResume an interrupted transfer
mkdir, rm, renameManage remote files
byeExit

Use a graphical client

If you prefer drag and drop, FileZilla, WinSCP (Windows) and Cyberduck (macOS) all speak SFTP. Choose protocol SFTP, port 22 (or yours), and your SSH user. They can use your SSH private key too (FileZilla and WinSCP may ask to convert it to PuTTY's .ppk format).

Which tool to use

  • scp: quick one-off copies from the command line.
  • sftp: browsing, several files, resuming large transfers.
  • rsync: repeated syncs or very large folders, since it transfers only changes.

Troubleshooting

  • Permission denied on upload: your user cannot write the target folder. Upload to your home directory, then move it with sudo.
  • Connection refused or timed out: same causes as SSH (wrong port, firewall, blocked IP). Check SSH login first.
  • scp: Received message too long: a startup file like .bashrc prints text for non-interactive shells. Wrap echo lines in a check for an interactive shell.
  • Files with spaces: quote the remote path: scp "root@ip:/root/my file.txt" .

scp and sftp FAQ

Is scp deprecated?

The old scp protocol is being phased out, but the scp command remains: recent OpenSSH versions use the SFTP protocol underneath, so it keeps working.

Is SFTP the same as FTPS?

No. SFTP runs over SSH on port 22; FTPS is FTP with TLS on ports 21/990. Both are encrypted.

Can I use SFTP with cPanel hosting?

Yes, if SSH access is enabled for your account: use your cPanel username and the SSH port your host provides.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.