Home·Terminal commands

sftp

Networking

Usage

sftp [-P <port>] <user>@<host>

An interactive file transfer tool riding on the ssh connection; the port flag is a capital `-P` rather than ssh's `-p`, and it cannot run remote shell commands, only its own put, get and ls.

Common flags

FlagMeaning
-P 2222Port, capital P. ssh uses lowercase -p for the same thing.
-i <key>Use a specific private key.
-rRecursive, for put -r and get -r on directories.
-b <batchfile>Run a list of commands without a prompt, for scripts.
put / get / ls / lcdIts own commands inside the session; lcd changes the local directory.

Examples

sftp -P 2222 deploy@example.com

Open an interactive transfer session.

sftp deploy@example.com:/var/log/app.log .

Fetch one file without entering the prompt.

When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does sftp do?

An interactive file transfer tool riding on the ssh connection; the port flag is a capital `-P` rather than ssh's `-p`, and it cannot run remote shell commands, only its own put, get and ls.

Q. How do I type it?

sftp [-P <port>] <user>@<host> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man sftp. This command sits under Networking.

Related commands

man page: man sftp