Glossary

SFTP

A secure way to transfer files to and from a server over an SSH connection.

In plain English A secure way to copy files between your computer and a server. Like dragging files into a folder, but the folder is on the server.

SFTP stands for SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → File Transfer Protocol. It moves files between your computer and a server over an encrypted SSH connection. It uses the same portPort A numbered door on a server. Each service listens behind its own door: web pages on 443, email on others, remote login on 22. More about Port →, usually 22, and the same login, password or key, as SSH itself. It is the secure replacement for plain FTP.

SFTP, FTP and FTPS

ProtocolEncryptedPortNotes
FTPNo21Sends passwords in plain text; avoid it
FTPSYes21 or 990FTP with TLS added; needs extra ports open
SFTPYes22Runs over SSH; one port, works through most firewalls

Despite the similar names, SFTP is not FTP over SSH; it is a separate protocol built into SSH.

Using it

Graphical clients such as FileZilla, Cyberduck and WinSCP connect with the server address, username, and password or key; choose SFTP as the protocol. From a terminal:

sftp alice@203.0.113.10
put site.zip
get backup.tar.gz

For single copies, scp is quicker, and rsync is best for folders because it only sends what changed.

SFTP-only accounts

To let a developer upload files without giving them a shell, create an account limited to SFTP and locked to one folder. In /etc/ssh/sshd_config:

Match User webdev
    ForceCommand internal-sftp
    ChrootDirectory /var/www/example.com

The chroot folder itself must be owned by root and not writable by the user. Control panelsControl panel A website you log into to manage your hosting with buttons and forms, instead of typing commands. cPanel and Plesk are the common ones. More about Control panel → create SFTP and FTP accounts like this for you.

Questions people ask

What is an SFTP server?

Any server running SSH is already an SFTP server, because SFTP is built into the SSH service (sshd). On Linux there is nothing extra to install: if you can log in with SSH, you can transfer files with SFTP using the same address, username and port.

What is an example of an SFTP transfer?

Uploading a website: connect with sftp exampleco@203.0.113.10, change to the site folder with cd /var/www/example.com, then send a file with put index.html. In FileZilla the same thing is host sftp://203.0.113.10, port 22, your username and password or key, then drag the file across.

Which port does SFTP use?

Port 22, the same as SSH. If your host moved SSH to another port, SFTP moves with it. See the list of common ports.

Is SFTP the same as FTPS?

No. FTPS is the old FTP protocol with TLS encryption added, using ports 21 and 990 plus a range of data ports. SFTP is a different protocol that runs inside SSH on a single port, which makes it simpler to firewallFirewall A gatekeeper that decides which connections are allowed into a server and blocks the rest. More about Firewall →.

How do I copy a whole folder with SFTP?

Use put -r foldername in the sftp command, or a graphical client. For large folders or repeated copies, rsync over SSH is faster because it only sends what changed; see how to back up a Linux server.