The Short Answer
Despite the similar names, SFTP is not FTP with security added. They are separate protocols that do the same job:
- FTP (File Transfer Protocol) dates from the early days of the internet. It uses a control connection on port 21 and separate data connections, and encrypts nothing.
- SFTP (SSH File Transfer Protocol) is part of SSH. It uses the SSH connection on port 22, and everything in it is encrypted.
A third option, FTPS, is FTP with TLS encryption added. It is covered below.
Side by Side
| SFTP | FTP | |
|---|---|---|
| Based on | SSH | Its own protocol |
| Port | 22 | 21 plus data ports |
| Connections | One | Control plus data |
| Encryption | Always | None |
| Login | Password or SSH key | Password |
| Firewall and NAT | One port, no trouble | Needs a passive range |
| Server on Linux | OpenSSH, already there | Extra FTP server |
Security
With plain FTP, the user name, the password, and the files cross the network as readable text. Anyone on the path, such as a shared network or a compromised router, can capture them. SFTP encrypts the login and the data inside the SSH session, checks the server's host key so you know you reached the right server, and can log in with an SSH key instead of a password.
Ports and Firewalls
FTP opens a new data connection for each file and each folder listing. In passive mode the client connects to a port the server picks from a range, so that range must be open in the server's firewall, and NAT makes the setup more fragile. The details are in port 21. SFTP needs nothing beyond the SSH port, usually 22; see port 22.
Where FTPS Fits
FTPS keeps the FTP protocol and wraps it in TLS, the encryption HTTPS uses. With explicit TLS the client connects to port 21 and upgrades the session; with implicit TLS it uses port 990 from the start. FTPS fixes the plain-text problem, but it keeps the separate data connections and needs a certificate on the server. It is a reasonable choice when a client or device supports only FTP-family protocols. More on all three is in what is FTP.
Which One to Use on Your Own Server
- SFTP for nearly everything: deploying a site, moving backups, giving a developer access. It works as soon as SSH works.
- FTPS when a client, a device, or an older application can speak only FTP but the data still crosses the internet.
- Plain FTP only for public downloads where nothing needs to stay private, and even there HTTPS is usually the better fit.
Using SFTP
From a terminal, connect and move files with put and get:
sftp user@your_server_ip
sftp> put site.tar.gz
sftp> get backup.sql
Graphical clients such as FileZilla and Cyberduck speak SFTP as well: choose SFTP as the protocol and use the SSH port. The full walkthrough is in how to use SFTP, and one-off copies are quicker with scp.
SFTP-Only Users
A user who should upload files but never get a shell can be limited to SFTP. In /etc/ssh/sshd_config, a Match User block with ForceCommand internal-sftp and a ChrootDirectory keeps that user inside one folder. The chroot folder and every folder above it must be owned by root and not writable by any other user or group, so give the user a writable subfolder inside it. Check the file with sudo sshd -t and keep your current session open while you test the change.
Moving from FTP to SFTP
- Make sure each FTP user has a system account that can log in with SFTP, or create SFTP-only users.
- Give users the new settings: protocol SFTP, the SSH port, and their login.
- When everyone has switched, stop and disable the FTP server and close port 21 and its passive range in the firewall.