SFTP (SSH File Transfer Protocol)

Definition

SFTP (SSH File Transfer Protocol, also called Secure File Transfer Protocol) is a network protocol that provides file access, transfer, and management over any reliable data stream. It runs over SSH (Secure Shell), providing encryption for both commands and data.

SFTP is NOT FTP over SSL/TLS (that is FTPS). SFTP uses a single SSH connection for both control and data, while FTPS uses separate control and data channels.

Key Concepts

  • Single Connection: Control and data share the same SSH connection (port 22 by default)
  • Authentication: SSH key-based or password authentication
  • Encryption: All data encrypted via SSH (AES, ChaCha20, etc.)
  • Resumable Transfers: Can resume interrupted file transfers
  • Directory Operations: List, create, delete, rename directories
  • File Operations: Upload, download, append, truncate, permissions

SFTP vs FTP vs FTPS

Feature SFTP FTP FTPS
Encryption Yes (SSH) No Yes (SSL/TLS)
Port 22 (single) 20, 21 (multiple) 989/990 or dynamic
Firewall Easy (single port) Hard (passive mode) Moderate
Protocol SSH-based FTP-based FTP over TLS
Authentication SSH keys/password Username/password Username/password/cert
Use Case Secure transfers Legacy systems Enterprise FTP

Common SFTP Commands

sftp user@host                    # Connect
sftp> put file.txt               # Upload
sftp> get file.txt               # Download
sftp> ls                         # List remote directory
sftp> mkdir dirname              # Create directory
sftp> rm file.txt                # Delete file
sftp> chmod 644 file.txt         # Change permissions
sftp> exit                       # Disconnect

SFTP Servers

Server Type Notes
OpenSSH sftp-server Built-in Ships with OpenSSH
vsftpd FTP/SFTP Popular FTP server with SFTP support
FileZilla Server FTP/SFTP GUI-based server
WinSCP Client Windows SFTP/SCP client
  • Ssh — older file transfer protocol, simpler than SFTP
  • FTP — unencrypted predecessor
  • FTPS — FTP over SSL/TLS (different from SFTP)
  • rsync — alternative file sync tool with SSH support

References