SFTP commands: how SFTP differs from FTP — and what you'll actually use

SFTP isn't FTP over SSH. It's a different protocol that looks the same at the client.

If you've used FTP, the SFTP client commands will feel almost identical: ls, cd, get, put, rm, mkdir. What's happening underneath, though, is completely different. Understanding the difference matters because it explains why SFTP is secure by default, why it doesn't have the firewall headaches FTP has, and why you can use SSH keys, MFA, and a single port for everything.

SFTP is not "FTP over SSH"

The name is misleading. SFTP — the SSH File Transfer Protocol, defined in draft-ietf-secsh-filexfer-02 — is not FTP wrapped in encryption. It's a separate protocol that runs as a subsystem of SSH. Different commands, different wire format, different security model.

Side-by-side comparison:

 FTPSFTP
Specification RFC 959 (1985) draft-ietf-secsh-filexfer-02 (2001, never finalised)
Default port 21 (control) + ephemeral data port 22 (single port, shared with SSH)
Encryption None by default. FTPS adds TLS but only after a successful upgrade negotiation. Always encrypted from the first byte — you can't connect without it.
Authentication Username + password, sent in cleartext over the control channel. SSH authentication: password, public key, host-based, or any combination including MFA.
Connection model Two connections: control on port 21, data on a separate port per transfer. One connection. Everything is multiplexed on the single SSH channel.
Wire format Text-based commands (USER, RETR, PASV) and response codes. Binary packets with length prefix, type byte, request ID, and payload.
NAT / firewall behaviour Notorious. Requires passive mode and often extra firewall rules to let the data ports through. Behaves like any other TCP service on one port. No special firewall configuration.

The single-port property is the practical one. With FTP, the data connection uses a fresh port per transfer, which means firewalls need to do FTP protocol inspection to know which ports to let through. With SFTP, all bytes — control, file content, status — flow on the same encrypted SSH connection on port 22. Nothing else to configure.

How to connect

The simplest way to start an SFTP session is from a terminal:

$ sftp alice@example.com
alice@example.com's password:
Connected to example.com.
sftp>

You can also connect using a public key instead of a password — the recommended approach for any account you'll use more than once:

$ ssh-keygen -t ed25519           # generates ~/.ssh/id_ed25519 and id_ed25519.pub
$ ssh-copy-id alice@example.com   # adds your public key to the server's authorized_keys
$ sftp alice@example.com           # no password prompt this time

Once connected, the prompt becomes sftp> and you can type commands interactively.

Use SSH keys whenever you can. They survive password rotations, don't appear in shell history, and are the only practical way to automate SFTP transfers without storing a plaintext password somewhere. The Stylus SFTP Server, like any modern SSH server, supports public-key authentication side-by-side with passwords, and lets you enforce key-only on specific accounts.

Moving around

CommandWhat it does
pwdPrint the current remote directory.
cd dirChange the remote directory. cd .. goes up one level.
lpwdPrint the current local directory — where downloads land by default.
lcd dirChange the local directory.

SFTP keeps a current directory on both ends of the connection. The l-prefixed commands act on the local side.

Listing files

CommandWhat it does
lsList the current remote directory.
ls -lLong format with permissions, owner, size, and timestamp.
ls patternGlob: ls *.csv lists only CSV files.
llsList the local directory (a quick check before put).

Transferring files

The most common SFTP commands. Everything is one-shot — no separate "open data connection" step.

CommandWhat it does
get fileDownload a file from the remote directory to the local directory.
get file destDownload and save under a different local name.
mget patternMulti-get — download every matching file. mget *.csv
put fileUpload a local file to the remote directory.
mput patternMulti-put — upload every matching local file.
reget fileResume an interrupted download from where it left off.
reput fileResume an interrupted upload from where it left off.

Behind the scenes each get turns into a sequence of SFTP packets: SSH_FXP_OPEN to open the file, repeated SSH_FXP_READ requests to pull bytes, and a final SSH_FXP_CLOSE. You won't see these in the prompt, but they're worth knowing if you ever read the protocol spec or have to debug an interop issue.

Creating, deleting, renaming

CommandWhat it does
mkdir nameCreate a directory on the server.
rmdir nameRemove an empty directory.
rm fileDelete a file.
rename old newRename or move a file.
symlink target linkCreate a symbolic link, where the server supports it.

Permissions and ownership

FTP doesn't have a standard way to change file permissions — you have to use SITE CHMOD, which is vendor-specific. SFTP, because it's modelled on POSIX file attributes, has these built in:

CommandWhat it does
chmod mode fileChange file mode. chmod 644 report.csv
chown uid fileChange owner (server-permitting).
chgrp gid fileChange group.

Help and exit

CommandWhat it does
? / helpList supported commands. Type help command for one-line help.
!commandRun command in a local shell (e.g. !ls lists the local directory).
!Open a local shell. Type exit to come back.
bye / exit / quitDisconnect and close the session.

What to do next

If you're coming from FTP, the muscle memory transfers directly: get, put, ls, cd all do what you expect. The wins are everything you don't have to think about — one port, encrypted, key-based auth, no separate data connection — and they're all happening because SFTP rides on SSH instead of being a layer over FTP.

A few practical next steps: