SFTP, the SSH File Transfer Protocol, is a binary protocol for transferring and managing remote files that runs as a subsystem inside an encrypted SSH connection. Among Internet protocols it is the standard choice when files must cross untrusted networks, because it inherits SSH confidentiality, integrity protection and authentication instead of adding security as an afterthought.
Despite the similar name, SFTP is not FTP with encryption. It was designed by the IETF Secure Shell working group as a completely separate protocol, and it offers full file system operations such as listing directories, renaming, deleting and changing permissions, not only uploads and downloads.
How SFTP works inside an SSH session
SFTP works by opening an SSH connection, authenticating the user, and then requesting the sftp subsystem on a new channel. All file operations travel as request and response packets on that single channel, so the server sees one TCP connection, normally on port 22.
Each packet carries a length field, a type byte and a request identifier. The identifier lets a client keep many requests in flight at the same time, which is how modern clients reach good throughput on high-latency links. The server answers each request with a status, a handle, data or attributes.
The table below shows the main packet types a client sends during a typical session and what each one does.
| Packet type | Purpose | Typical response |
|---|---|---|
| SSH_FXP_INIT | Negotiate the protocol version | SSH_FXP_VERSION |
| SSH_FXP_OPEN | Open or create a file | Handle or status |
| SSH_FXP_READ / WRITE | Transfer a block at an offset | Data or status |
| SSH_FXP_OPENDIR / READDIR | List a directory | Names with attributes |
| SSH_FXP_STAT / SETSTAT | Read or change attributes | Attributes or status |
| SSH_FXP_RENAME / REMOVE | Rename or delete a file | Status |
Because reads and writes specify an explicit byte offset, SFTP supports resuming interrupted transfers and random access within large files. A client can restart a failed upload at the last confirmed offset instead of sending the whole file again.
Protocol versions and specifications
SFTP never became a finished IETF standard; it exists as a series of Internet-Drafts numbered as versions 3 to 6. In practice, version 3 is the de facto standard, because OpenSSH, the most widely deployed implementation, has supported only that version for decades.
| Version | Notable additions | Real-world support |
|---|---|---|
| Version 3 | Core file operations, POSIX-style attributes | Universal, OpenSSH default |
| Version 4 | Richer attributes, text mode hints | Some commercial servers |
| Version 5 | Extended open flags | Rare |
| Version 6 | Byte-range locking, link handling | Limited, mostly Windows servers |
Vendors fill gaps in version 3 with named extensions, such as posix-rename@openssh.com for atomic renames, statvfs@openssh.com for free space queries and fsync@openssh.com for flushing data to disk. A robust client checks which extensions the server advertises in its version reply before relying on them.
SFTP compared with FTP, FTPS and SCP
SFTP differs from FTP and FTPS mainly in its transport model: it uses one encrypted channel, whereas FTP families split control and data into separate connections. That split makes FTP difficult behind firewalls and NAT, while SFTP needs only one open port.
The following comparison summarizes the protocols that administrators most often weigh against each other.
| Protocol | Security layer | Ports | File management |
|---|---|---|---|
| FTP | None, credentials in clear text | 21 plus a data port | Yes |
| FTPS | TLS on control and data channels | 21 or 990 plus data ports | Yes |
| SFTP | SSH transport encryption | 22 only | Yes, extensive |
| SCP | SSH transport encryption | 22 only | Copy only |
| HTTPS upload | TLS | 443 | Depends on the application |
SCP shares the SSH transport but historically relied on a remote shell command, which caused quoting problems and security flaws. Recent OpenSSH releases therefore run the scp command over the SFTP protocol by default. FTPS remains relevant where organizations already operate an X.509 certificate infrastructure and partners require it.
Authentication and security properties
SFTP security comes entirely from the SSH transport layer, which provides key exchange, encryption, integrity checks and server authentication through host keys. The client must verify the host key fingerprint on first contact; skipping this step leaves the session open to man-in-the-middle attacks.
Users authenticate with passwords, public keys, certificates or keyboard-interactive methods such as one-time codes. For automated transfers, public key authentication with a dedicated key per integration is the accepted practice, because keys can be restricted and revoked individually.
- Chroot jails confine an SFTP user to a single directory tree on the server.
- The
internal-sftpoption in OpenSSH serves files without granting shell access. - Forced commands in authorized keys limit what a key is allowed to do.
- Modern ciphers such as AES-GCM and ChaCha20-Poly1305 provide authenticated encryption.
Choosing and configuring SFTP in practice
SFTP is the right choice when an organization needs scheduled, scripted file exchange with partners, banks or suppliers over the public Internet. It suits batch workloads such as payroll files, data feeds and backups better than interactive web sharing.
| Situation | Recommended choice | Reason |
|---|---|---|
| Automated partner exchange | SFTP with key authentication | One port, scriptable, auditable |
| Partner mandates certificates | FTPS | Fits existing TLS certificate policy |
| Ad hoc sharing with end users | HTTPS file sharing service | No client software needed |
| Very large datasets over long distances | SFTP with parallel requests or a specialized tool | Latency limits single-stream throughput |
| Quick copy between servers | scp or rsync over SSH | Simple syntax, same security |
Performance depends heavily on the number of outstanding requests and the block size. Clients that send one request and wait for the reply suffer badly on links with 100 ms or more of round-trip time, while pipelined clients can approach line speed.
Limitations and common mistakes
The most common SFTP problems come from inconsistent implementations and careless key handling rather than from weaknesses in the protocol itself. Experienced administrators watch for the following issues.
- Rename semantics vary: standard version 3 rename fails if the target exists, so atomic replacement needs the posix-rename extension.
- No built-in checksum in version 3; integrity of the final file is often verified separately with a hash.
- Accepting unknown host keys automatically in scripts defeats server authentication.
- Shared keys across partners make revocation and auditing impossible.
- Clock and timestamp handling differs between servers, which confuses synchronization tools.
Another misconception is that SFTP encrypts files at rest. It protects data only in transit; once stored on the server, files are as safe as the server file system and its access controls.
In everyday language
SFTP is a way to send files to another computer and manage them there through a locked, private tunnel. Anyone watching the network sees only scrambled data, not the files or the password.
Think of it as a secure courier that also lets you rearrange the folders at the destination. You can upload, download, rename or delete files, and everything travels through one guarded door instead of several.
Seen in the real world
A mid-sized retailer sends its daily sales file to its bank every night at 01:00. A scheduled job connects to the bank’s SFTP server on port 22, authenticates with a dedicated Ed25519 key, and uploads a 40 MB file to a folder named for that day.
The script uploads under a temporary name, verifies the size, and then renames the file so the bank never processes a half-written upload. The bank’s server restricts the account to one chroot directory with no shell access. When the retailer later changes payment providers, the bank simply revokes that single key, and the audit log shows every transfer made during the contract.