Once you have SSH access to a server, you automatically have a secure way to transfer files. SSH includes two native protocols for this: SCP (Secure Copy Protocol) and SFTP (SSH File Transfer Protocol). Both run over the same encrypted SSH connection, so no extra ports need to be open and no separate firewall rules need to be configured. If you can SSH into the server, you can transfer files.
The short answer on which to use: SCP for quick one-off copies when you know exactly what file you want to move, SFTP when you need to browse directories or manage files interactively, and rsync when you are syncing large directories or running the transfer repeatedly.
Here is how each one actually works.
SCP
SCP works like the standard cp command, but with remote paths. You specify a source and a destination, and it copies the file.
The basic syntax:
scp [source] [destination]
Remote paths use the format user@host:/path/to/file.
Copy a file from your local machine to a server:
scp myfile.txt root@192.168.1.100:/var/www/
Copy a file from the server to your local machine:
scp root@192.168.1.100:/var/log/syslog ./
Copy an entire directory, recursively:
scp -r myproject/ root@192.168.1.100:/var/www/
SCP is a one-shot tool. You run it, it copies the file, it exits. You cannot browse directories or preview what is on the server before transferring. If you need to explore the filesystem first, use SFTP.
One thing worth knowing: the SCP protocol itself was deprecated in OpenSSH 9.0 (released 2022). The underlying SCP protocol had some behavioral quirks, particularly around how it handled filenames with special characters. The scp command in modern OpenSSH versions actually uses the SFTP protocol under the hood by default. You do not need to change your workflow, but it explains why you might see slightly different behavior between older and newer systems.
To use a private key file with SCP (same as SSH):
scp -i ~/.ssh/my-key.pem file.txt ec2-user@server:/home/ec2-user/
To specify a non-standard port:
scp -P 2222 file.txt user@server:/tmp/
Note the capital -P for port with SCP, versus lowercase -p for port with SSH. This is a common source of muscle-memory mistakes.
SFTP
SFTP opens an interactive session rather than a one-shot transfer. You get a prompt where you can navigate directories, list files, upload and download, delete files, and manage permissions.
Connect to a server:
sftp user@192.168.1.100
After connecting, your prompt changes to sftp>. From there:
ls # list files on the remote server
lls # list files on your local machine
cd /var/www # change remote directory
lcd ~/Downloads # change local directory
get error.log # download a file to your local machine
put update.zip # upload a file to the remote server
mget *.log # download multiple files matching a pattern
mput *.jpg # upload multiple files matching a pattern
rm oldfile.txt # delete a remote file
mkdir newdir # create a remote directory
chmod 644 file.txt # change permissions on a remote file
exit # close the session
SFTP is useful when you are not sure where a file is and need to look around before downloading it, or when you need to transfer multiple files without writing a loop.
SFTP also supports non-interactive batch mode, useful for scripting:
sftp user@server << 'EOF'
cd /var/www
put deploy.tar.gz
EOF
Graphical SFTP clients
You do not have to use the command line for SFTP. The protocol is robust and well-documented, and many graphical tools support it:
- Windows: FileZilla or WinSCP
- macOS: Cyberduck or Transmit
- Linux: FileZilla or Nautilus (which has built-in SFTP support through the
sftp://address bar)
These tools give you a drag-and-drop file browser that tunnels everything over SSH. FileZilla is free and cross-platform; Transmit is macOS-only and paid but has a noticeably better interface.
To configure a graphical client, you typically need:
- Hostname: your server's IP or domain
- Port: 22 (or whatever SSH uses)
- Username: your server username
- Authentication: either your SSH password or your private key file
The private key format varies by client. FileZilla accepts OpenSSH format. WinSCP historically preferred PuTTY's PPK format, though newer versions handle both.
When to use rsync instead
For syncing directories, deploying code, or any transfer you run repeatedly, neither SCP nor SFTP is the right tool.
rsync calculates the difference between the source and destination and only transfers the parts that changed. On a large directory where most files have not changed, this is dramatically faster than copying everything each time.
rsync -avz --progress myproject/ user@192.168.1.100:/var/www/myproject/
The flags:
-a(archive): preserves permissions, timestamps, symlinks, and ownership-v(verbose): shows what is being transferred-z(compress): compresses data during transfer, useful for slow connections
rsync also resumes interrupted transfers. If a large file transfer stops halfway through, rsync picks up where it left off. SCP starts over from the beginning.
By default, rsync uses SSH as its transport layer, so it is just as secure and uses the same credentials and keys.
For deploying a web project:
rsync -avz --exclude '.git' --exclude 'node_modules' ./build/ deploy@server:/var/www/app/
The --exclude options skip directories you do not need on the server.
rsync also has a --dry-run flag that shows what would be transferred without actually doing it. Useful for checking you have the source and destination paths correct before committing to a large transfer.
Troubleshooting
"Permission denied" on transfer
If you can SSH into the server but get "Permission denied" during an SCP or SFTP transfer, the issue is usually file permissions on the target directory. If you log in as ubuntu but are trying to write to /var/www/html/ (owned by root or www-data), the transfer will fail.
You cannot easily sudo scp. The practical solution is to upload to your home directory first, then SSH in and move the file:
scp myfile.txt ubuntu@server:/home/ubuntu/
ssh ubuntu@server "sudo mv /home/ubuntu/myfile.txt /var/www/html/"
"No such file or directory"
Check whether the destination directory exists on the server. SCP and SFTP will not create intermediate directories automatically.
Key-based auth for SCP
If your SSH connection uses a key, SCP uses the same key automatically if it is in the default location. If you need to specify it explicitly:
scp -i ~/.ssh/mykey.pem file.txt user@server:/tmp/
Large file transfers
For transfers of several gigabytes over a slow or unreliable connection, rsync with -z (compression) and a screen or tmux session is more reliable than SCP. If the connection drops, rsync resumes; SCP starts over.
Transferring files from a browser
If you are using SSHDock from a Chromebook or tablet, a native graphical SFTP client is not available. The browser terminal gives you full command-line access, so you can download files directly to the server using wget or curl, manage files with standard shell commands, and use rsync for syncing if the remote server has it available. For downloading files from the server to your local machine, some browser-based clients include a file download feature; check SSHDock's current feature set for what is available.