SFTP(1)

๐Ÿ“ฆ
version 10.5p1 ยท 6 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, debian trixie, fedora 43, fedora 44, freebsd 14.5, freebsd 15.1, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

๐ŸŽ€ SFTP(1) โ€” General Commands Manual โœจ

okay bestie, this is the manual page for sftp ๐Ÿ’– It's the General Commands Manual, and we're gonna go through the whole thing together ๐Ÿซถ

๐ŸŒธ NAME ๐ŸŒธ

sftp โ€” OpenSSH secure file transfer ๐Ÿฆ‹

๐Ÿ’… SYNOPSIS ๐Ÿ’…

sftp [-46AaCfNpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
     [-D sftp_server_command] [-F ssh_config] [-i identity_file]
     [-J destination] [-l limit] [-o ssh_option] [-P port]
     [-R num_requests] [-S program] [-s subsystem | sftp_server]
     [-X sftp_option] destination

โœจ DESCRIPTION โœจ

okay so sftp is a file transfer program, kinda like ftp(1), except it does everything over an encrypted ssh(1) transport ๐Ÿ” It can also borrow a bunch of ssh features, like public key authentication and compression. iconic behavior tbh ๐Ÿ‘‘

The destination can be written as [user@]host[:path], or as a URI that looks like sftp://[user@]host[:port][/path] ๐Ÿงš

If the destination has a path and that path isn't a directory, sftp will grab the files for you automatically when you're using a non-interactive authentication method. If you're doing interactive authentication instead, it waits until you've logged in successfully and then does the fetching ๐Ÿ™ˆ

If there's no path, or the path is a directory, sftp logs you into the host and drops you into interactive command mode. If you gave it a remote directory, it'll change into that directory first ๐Ÿ’œ You can add a trailing slash to force the path to be treated as a directory, which is a super handy little trick ๐Ÿ“

Heads up: the destination formats use colons to separate host names from path names or port numbers. So IPv6 addresses have to be wrapped in square brackets, otherwise things get ambiguous and nobody wants that ๐Ÿ˜ญ

Here are the options, bestie ๐ŸŒˆ


๐ŸŒท OPTIONS ๐ŸŒท

  • -4 โ€” Forces sftp to use IPv4 addresses only. Strictly IPv4, no exceptions ๐Ÿซถ
  • -6 โ€” Forces sftp to use IPv6 addresses only. IPv6 or bust ๐Ÿ’…
  • -A โ€” Lets you forward ssh-agent(1) to the remote system. By default, no authentication agent gets forwarded, so you have to ask for it explicitly โœจ
  • -a โ€” Tries to pick up interrupted transfers where they left off, instead of overwriting the partial or complete copies that are already there ๐Ÿฆ‹
โš ๏ธ Be careful with this one! If the partial contents don't match what's being transferred, the resulting file is likely to be corrupt ๐Ÿ’€
  • -B buffer_size โ€” Sets the size of the buffer sftp uses when it transfers files. Bigger buffers need fewer round trips, but they eat more memory. The default is 32768 bytes ๐Ÿงš
  • -b batchfile โ€” batch mode reads a list of commands from an input batchfile instead of stdin. There's no user interaction in batch mode, so you should pair it with non-interactive authentication. That way you won't have to type a password when connecting. (Check sshd(8) and ssh-keygen(1) for the deets ๐Ÿ”‘)

A batchfile of - means standard input ๐ŸŽ€ sftp will abort if any of these commands fail: get, put, reget, reput, rename, ln, rm, mkdir, chdir, ls, lchdir, copy, cp, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir.

You can suppress the abort-on-error behavior for a single command by starting that command with a - character. For example: -rm /tmp/blah*. And if you don't want the command echoed, start it with an @ character instead. You can combine these two prefixes in any order, like -@ls /bsd ๐Ÿ’…

  • -C โ€” Turns on compression, using ssh's -C flag ๐ŸŒˆ
  • -c cipher โ€” Picks the cipher used to encrypt the data transfers. This option gets passed straight through to ssh(1) โœจ
  • -D sftp_server_command โ€” Connects directly to a local sftp server, skipping ssh(1) entirely. You can give it a command and its arguments, like "/path/sftp-server -el debug3". This one's really useful when you're debugging the client and server together ๐Ÿ”
  • -F ssh_config โ€” Points ssh(1) at an alternative per-user configuration file. This gets passed straight through to ssh(1) ๐Ÿซง
  • -f โ€” Asks for files to be flushed to disk right after the transfer finishes. When you're uploading, this only kicks in if the server implements the "fsync@openssh.com" extension ๐Ÿ’พ
  • -i identity_file โ€” Picks the file where the identity (private key) for public key authentication gets read from. This option is passed straight through to ssh(1) ๐Ÿ”‘
  • -J destination โ€” Connects to the target host by first making an sftp connection to the jump host described by destination. From there, it sets up a TCP forwarding to the final destination. You can chain several jump hops by separating them with commas. This is a shortcut for the ProxyJump configuration directive, and the option is passed straight through to ssh(1) ๐Ÿฆ‹
  • -l limit โ€” Limits how much bandwidth gets used, measured in Kbit/s ๐Ÿข
  • -N โ€” Turns quiet mode off. This is handy when you want to override the implicit quiet mode that the -b flag sets ๐ŸŽ€
  • -o ssh_option โ€” Lets you pass options to ssh using the format from ssh_config(5). This is great for options that don't have their own sftp command-line flag. For example, to use an alternate port, you'd write sftp -oPort=24. For the full details on the options below and what values they accept, check out ssh_config(5) ๐Ÿงš

These are the options you can pass this way:

  • AddKeysToAgent
  • AddressFamily
  • BatchMode
  • BindAddress
  • BindInterface
  • CASignatureAlgorithms
  • CanonicalDomains
  • CanonicalizeFallbackLocal
  • CanonicalizeHostname
  • CanonicalizeMaxDots
  • CanonicalizePermittedCNAMEs
  • CertificateFile
  • ChannelTimeout
  • CheckHostIP
  • Ciphers
  • ClearAllForwardings
  • Compression
  • ConnectTimeout
  • ConnectionAttempts
  • ControlMaster
  • ControlPath
  • ControlPersist
  • DynamicForward
  • EnableEscapeCommandline
  • EnableSSHKeysign
  • EscapeChar
  • ExitOnForwardFailure
  • FingerprintHash
  • ForkAfterAuthentication
  • ForwardAgent
  • ForwardX11
  • ForwardX11Timeout
  • ForwardX11Trusted
  • GSSAPIAuthentication
  • GSSAPIDelegateCredentials
  • GatewayPorts
  • GlobalKnownHostsFile
  • HashKnownHosts
  • Host
  • HostKeyAlgorithms
  • HostKeyAlias
  • HostbasedAcceptedAlgorithms
  • HostbasedAuthentication
  • Hostname
  • IPQoS
  • IdentitiesOnly
  • IdentityAgent
  • IdentityFile
  • IgnoreUnknown
  • Include
  • KbdInteractiveAuthentication
  • KbdInteractiveDevices
  • KexAlgorithms
  • KnownHostsCommand
  • LocalCommand
  • LocalForward
  • LogLevel
  • LogVerbose
  • MACs
  • NoHostAuthenticationForLocalhost
  • NumberOfPasswordPrompts
  • ObscureKeystrokeTiming
  • PKCS11Provider
  • PasswordAuthentication
  • PermitLocalCommand
  • PermitRemoteOpen
  • Port
  • PreferredAuthentications
  • ProxyCommand
  • ProxyJump
  • ProxyUseFdpass
  • PubkeyAcceptedAlgorithms
  • PubkeyAuthentication
  • RekeyLimit
  • RemoteCommand
  • RemoteForward
  • RequestTTY
  • RequiredRSASize
  • RevokedHostKeys
  • SecurityKeyProvider
  • SendEnv
  • ServerAliveCountMax
  • ServerAliveInterval
  • SessionType
  • SetEnv
  • StdinNull
  • StreamLocalBindMask
  • StreamLocalBindUnlink
  • StrictHostKeyChecking
  • SyslogFacility
  • TCPKeepAlive
  • Tag
  • Tunnel
  • TunnelDevice
  • UpdateHostKeys
  • User
  • UserKnownHostsFile
  • VerifyHostKeyDNS
  • VisualHostKey
  • XAuthLocation

โœจ INTERACTIVE COMMANDS โœจ

okay so once you're in interactive mode, sftp understands a bunch of commands that are basically like ftp(1)'s. ๐Ÿ’… Commands are case insensitive, so CD and cd are the same vibe. ๐Ÿซถ If a pathname has spaces in it, it must be wrapped in quotes. Also, any special characters in a pathname that glob(3) recognizes need to be escaped with backslashes (\). no cap, that's the one thing that will trip you up ๐Ÿ˜ญ

  • bye โ€” quit sftp ๐Ÿ‘‹
  • cd [path] โ€” changes the remote directory to path. If you don't give a path, it sends you back to the directory your session started in ๐Ÿ 
  • chgrp [-h] grp path โ€” changes the group of the file at path to grp. path can use glob(7) characters and hit multiple files at once ๐ŸŽฏ grp has to be a numeric GID, bestie.
    • If you pass the -h flag, symlinks won't be followed. โ›“๏ธโ€๐Ÿ’ฅ This only works on servers that implement the "lsetstat@openssh.com" extension, so check your server first ๐Ÿ”
  • chmod [-h] mode path โ€” changes the permissions of the file at path to mode. path can use glob(7) characters and match multiple files ๐Ÿ”
    • Same deal with -h: symlinks won't be followed. It's also only supported by servers that implement the "lsetstat@openssh.com" extension ๐Ÿ’€
  • chown [-h] own path โ€” changes the owner of the file at path to own. path can use glob(7) characters and match multiple files ๐Ÿงš own has to be a numeric UID.
    • -h means symlinks aren't followed, and yep, it only works on servers with the "lsetstat@openssh.com" extension ๐Ÿซ 
  • copy oldpath newpath โ€” copies a remote file from oldpath to newpath ๐Ÿ“„โœจ
    • This one is only supported by servers that implement the "copy-data" extension, so it's not guaranteed everywhere ๐Ÿ™ˆ
  • cp oldpath newpath โ€” an alias for the copy command, so it does the exact same thing ๐Ÿ‘ฏ
  • df [-hi] [path] โ€” shows usage info for the filesystem holding the current directory, or path if you give one ๐Ÿ’พ
    • -h shows the capacity info with "human-readable" suffixes, so you get nice big-unit numbers instead of a wall of digits ๐Ÿ“
    • -i adds inode information on top of the capacity info ๐Ÿ”ข
    • This command only works on servers that implement the โ€œstatvfs@openssh.comโ€ extension, so if your server doesn't have it, it's gonna be a no-go ๐Ÿฅฒ
  • exit โ€” quit sftp ๐Ÿ‘‹ (same as bye, literally)
  • get [-afpR] remote-path [local-path] โ€” downloads remote-path and saves it on your local machine ๐Ÿ“ฅ If you don't name a local-path, it keeps the same name it had on the remote machine. remote-path can use glob(7) characters and match multiple files. If it does match multiple files and you give a local-path, then that local-path has to be a directory ๐Ÿ“
    • -a tries to resume partial transfers of existing files โฏ๏ธ Heads up though: resuming assumes any partial local copy matches the remote copy. If the remote contents are different from the partial local copy, the final file is likely to be corrupt. ๐Ÿ˜ญ Not a vibe.
    • -f tells sftp to call fsync(2) once the transfer finishes, which flushes the file out to disk ๐Ÿ’ง
    • -p copies over the full file permissions and access times too ๐Ÿ”โฐ
    • -R copies directories recursively ๐ŸŒณ sftp does not follow symbolic links during recursive transfers, so those links stay links (no sneaky following) ๐Ÿฆ‹
  • help โ€” displays the help text ๐Ÿ†˜
  • lcd [path] โ€” changes the local directory to path. If you don't give a path, it takes you to the local user's home directory ๐Ÿก
  • lls [ls-options [path]] โ€” displays a local directory listing of path, or of the current directory if you skip path ๐Ÿ“‚ ls-options can be any flags your local system's ls(1) command supports. path can use glob(7) characters and match multiple files ๐ŸŽ€
  • lmkdir path โ€” creates a local directory at path ๐Ÿ› ๏ธ
  • ln [-s] oldpath newpath โ€” creates a link from oldpath to newpath ๐Ÿ”— With -s, the link is a symbolic link. Without it, you get a hard link. โœจ
  • lpwd โ€” prints your local working directory ๐Ÿ“
  • ls [-1afhlnrSt] [path] โ€” displays a remote directory listing of path, or the current directory if you don't give one ๐Ÿ—‚๏ธ path can use glob(7) characters and match multiple files. These flags are recognized and change how ls behaves:
    • -1 โ€” single column output, one thing per line ๐Ÿ“œ
    • -a โ€” lists files that start with a dot (.), so the hidden ones show up ๐Ÿ‘€
    • -f โ€” doesn't sort the listing. The default sort is lexicographical, so this one turns it off ๐Ÿ™…โ€โ™€๏ธ
    • -h โ€” when used with a long format option, it uses unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, and Exabyte. It keeps the number of digits to four or fewer by using powers of 2 for sizes (K=1024, M=1048576, etc.) ๐Ÿ“
    • -l โ€” shows extra details, including permissions and ownership info ๐Ÿ”
    • -n โ€” gives you a long listing where user and group info is shown as numbers instead of names ๐Ÿ”ข
    • -r โ€” reverses the sort order ๐Ÿ”„
    • -S โ€” sorts the listing by file size ๐Ÿ‹๏ธ
    • -t โ€” sorts the listing by last modification time โณ
  • lumask umask โ€” sets your local umask to umask ๐ŸŽญ
  • mkdir path โ€” creates a remote directory at path ๐ŸŒธ
  • progress โ€” toggles the progress meter on or off ๐Ÿ“Š
  • put [-afpR] local-path [remote-path] โ€” uploads local-path and stores it on the remote machine โ˜๏ธ If you don't give a remote-path, it keeps the same name it had locally. local-path can use glob(7) characters and match multiple files. If it does and you give a remote-path, then remote-path has to be a directory ๐Ÿ“
    • -a tries to resume partial transfers of existing files โฏ๏ธ Resumption assumes any partial copy of the remote file matches the local copy. If the local contents are different from the remote copy, the result is likely to be corrupt. ๐Ÿ’€
    • -f sends a request to the server to call fsync(2) after the file has been transferred. This only works on servers that implement the "fsync@openssh.com" extension ๐Ÿงƒ
    • -p copies over full file permissions and access times too ๐Ÿ”โฐ
    • -R copies directories recursively ๐ŸŒณ sftp does not follow symbolic links during recursive transfers, same as with get ๐Ÿฆ‹
  • pwd โ€” displays the remote working directory ๐Ÿ“
  • quit โ€” quit sftp ๐Ÿ‘‹ (yep, another one that does the same thing)
  • reget [-fpR] remote-path [local-path] โ€” resumes the download of remote-path. It's equivalent to get with the -a flag set ๐Ÿ”
  • reput [-fpR] local-path [remote-path] โ€” resumes the upload of local-path. It's equivalent to put with the -a flag set ๐Ÿ”
  • rename oldpath newpath โ€” renames a remote file from oldpath to newpath โœ๏ธ
  • rm path โ€” deletes the remote file at path ๐Ÿ—‘๏ธ
  • rmdir path โ€” removes the remote directory at path ๐Ÿซง
  • symlink oldpath newpath โ€” creates a symbolic link from oldpath to newpath ๐Ÿ”—
  • version โ€” displays the sftp protocol version ๐Ÿ”ข
  • !command โ€” runs command in your local shell ๐Ÿš
  • ! โ€” escapes to your local shell ๐Ÿƒโ€โ™€๏ธ
  • ? โ€” a synonym for help ๐Ÿ™‹โ€โ™€๏ธ

โœจ SEE ALSO โœจ

ftp(1), ls(1), scp(1), ssh(1), ssh-add(1), ssh-keygen(1), ssh_config(5), glob(7), sftp-server(8), sshd(8) ๐Ÿ“š

The SFTP protocol itself comes from T. Ylonen and S. Lehtinen, SSH File Transfer Protocol, draft-ietf-secsh-filexfer-00.txt, January 2001, which is listed as work in progress material ๐Ÿงช


Ok that's the whole page, bestie! ๐Ÿซถ It's the Debian version from December 6, 2024, and the manual page is SFTP(1), so you're all set ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from