SFTP

Also known as: SSH File Transfer Protocol

On this page 8

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 typePurposeTypical response
SSH_FXP_INITNegotiate the protocol versionSSH_FXP_VERSION
SSH_FXP_OPENOpen or create a fileHandle or status
SSH_FXP_READ / WRITETransfer a block at an offsetData or status
SSH_FXP_OPENDIR / READDIRList a directoryNames with attributes
SSH_FXP_STAT / SETSTATRead or change attributesAttributes or status
SSH_FXP_RENAME / REMOVERename or delete a fileStatus
Core SFTP request types

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.

VersionNotable additionsReal-world support
Version 3Core file operations, POSIX-style attributesUniversal, OpenSSH default
Version 4Richer attributes, text mode hintsSome commercial servers
Version 5Extended open flagsRare
Version 6Byte-range locking, link handlingLimited, mostly Windows servers
SFTP protocol versions in practice

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.

ProtocolSecurity layerPortsFile management
FTPNone, credentials in clear text21 plus a data portYes
FTPSTLS on control and data channels21 or 990 plus data portsYes
SFTPSSH transport encryption22 onlyYes, extensive
SCPSSH transport encryption22 onlyCopy only
HTTPS uploadTLS443Depends on the application
Secure and legacy file transfer protocols

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-sftp option 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.

SituationRecommended choiceReason
Automated partner exchangeSFTP with key authenticationOne port, scriptable, auditable
Partner mandates certificatesFTPSFits existing TLS certificate policy
Ad hoc sharing with end usersHTTPS file sharing serviceNo client software needed
Very large datasets over long distancesSFTP with parallel requests or a specialized toolLatency limits single-stream throughput
Quick copy between serversscp or rsync over SSHSimple syntax, same security
Deciding on a transfer method

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.