SCP vs SFTP: How to transfer files over SSH
Once you have SSH access to a server, you automatically have a secure way to transfer files. That access comes through two native protocols: SCP (Secure Copy Protocol) and SFTP (SSH File Transfer Protocol).
Because both run over the exact same SSH connection, there are no extra ports to open and no separate firewall rules to configure. If you can SSH into the box, you can transfer files.
The Verdict (TL;DR): Use SCP for one-off, quick transfers where you know exactly what file you want to move. Use SFTP when you need to explore a directory, rename files, or pause/resume transfers. For syncing large directories or deploying code, ignore both and use rsync.
Here is how each protocol actually works in practice.
SCP: The Quick One-Liner
SCP works exactly like the standard cp (copy) command, but for remote paths. It is incredibly fast, but it is a "one-shot" tool—you execute it, it copies the file, and it exits. You cannot browse directories or see what is on the server before copying.
The basic syntax is:
scp [source] [destination]
Remote paths are formatted as user@host:/path/to/file.
Common SCP Examples:
Copy a file from your local machine to the 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 (using the -r recursive flag):
scp -r myproject/ root@192.168.1.100:/var/www/
(Note: While SCP is deeply ingrained in muscle memory for many developers, the underlying SCP protocol was deprecated in OpenSSH 9.0. Modern versions of the scp command actually use the SFTP protocol under the hood anyway. You don't need to change your habits, but it's good to know.)
SFTP: The Interactive File Browser
SFTP opens an interactive session. Instead of a one-shot copy, you get a dedicated prompt where you can navigate directories, list files, transfer in both directions, and manage permissions.
Connect by typing:
sftp user@192.168.1.100
Once connected, your prompt changes to sftp>. From here, you have a set of commands that manage both the remote server and your local machine simultaneously:
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
rm oldfile.txt # delete a remote file
exit # close the session
SFTP is especially useful if you aren't exactly sure where the file is located and need to look around before downloading it.
Graphical SFTP Clients
You don't have to use the command line for SFTP. Because it's a robust protocol, many GUI tools support it natively:
- Windows: FileZilla or WinSCP
- macOS: Cyberduck or Transmit
These tools give you a familiar drag-and-drop file browser interface, securely tunneling all operations over SSH.
When to just use rsync instead
If you are syncing large directories (like node_modules or media folders), or running a transfer repeatedly, neither SCP nor SFTP is the right tool.
You should use rsync.
rsync is significantly faster because it calculates the delta (the differences) between the source and destination. If a transfer is interrupted, rsync will pick up exactly where it left off, whereas SCP will start completely over from the beginning.
rsync -avz --progress myproject/ user@192.168.1.100:/var/www/myproject/
By default, rsync uses SSH as its transport layer, so it is just as secure.
Troubleshooting Transfers
"Permission Denied" Errors
If you can SSH into the server but get a "Permission Denied" error during an SCP/SFTP transfer, the issue is almost always file permissions on the target directory.
For example, if you log in as ubuntu but try to scp a file into /var/www/html/ (which is owned by root or www-data), the transfer will fail. You cannot sudo scp easily. The solution is to upload the file to your user's home directory (/home/ubuntu/) first, then SSH into the server and use sudo mv to move the file to its final destination.
Transferring via Browser
If you are using a browser-based client like SSHDock because you are on a Chromebook or tablet, native drag-and-drop SFTP clients won't be available. However, because SSHDock gives you a full terminal, you can easily use command-line utilities (like downloading files directly to the server using wget or curl) to manage your remote filesystem without needing a dedicated FTP client.