SFTP(1)
๐ 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โ Forcessftpto use IPv4 addresses only. Strictly IPv4, no exceptions ๐ซถ-6โ Forcessftpto use IPv6 addresses only. IPv6 or bust ๐-Aโ Lets you forwardssh-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 ๐
-Bbuffer_size โ Sets the size of the buffersftpuses when it transfers files. Bigger buffers need fewer round trips, but they eat more memory. The default is 32768 bytes ๐ง-bbatchfile โ 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. (Checksshd(8)andssh-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, usingssh's-Cflag ๐-ccipher โ Picks the cipher used to encrypt the data transfers. This option gets passed straight through tossh(1)โจ-Dsftp_server_command โ Connects directly to a local sftp server, skippingssh(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 ๐-Fssh_config โ Pointsssh(1)at an alternative per-user configuration file. This gets passed straight through tossh(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 ๐พ-iidentity_file โ Picks the file where the identity (private key) for public key authentication gets read from. This option is passed straight through tossh(1)๐-Jdestination โ 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 theProxyJumpconfiguration directive, and the option is passed straight through tossh(1)๐ฆ-llimit โ 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-bflag sets ๐-ossh_option โ Lets you pass options tosshusing the format fromssh_config(5). This is great for options that don't have their ownsftpcommand-line flag. For example, to use an alternate port, you'd writesftp -oPort=24. For the full details on the options below and what values they accept, check outssh_config(5)๐ง
These are the options you can pass this way:
AddKeysToAgentAddressFamilyBatchModeBindAddressBindInterfaceCASignatureAlgorithmsCanonicalDomainsCanonicalizeFallbackLocalCanonicalizeHostnameCanonicalizeMaxDotsCanonicalizePermittedCNAMEsCertificateFileChannelTimeoutCheckHostIPCiphersClearAllForwardingsCompressionConnectTimeoutConnectionAttemptsControlMasterControlPathControlPersistDynamicForwardEnableEscapeCommandlineEnableSSHKeysignEscapeCharExitOnForwardFailureFingerprintHashForkAfterAuthenticationForwardAgentForwardX11ForwardX11TimeoutForwardX11TrustedGSSAPIAuthenticationGSSAPIDelegateCredentialsGatewayPortsGlobalKnownHostsFileHashKnownHostsHostHostKeyAlgorithmsHostKeyAliasHostbasedAcceptedAlgorithmsHostbasedAuthenticationHostnameIPQoSIdentitiesOnlyIdentityAgentIdentityFileIgnoreUnknownIncludeKbdInteractiveAuthenticationKbdInteractiveDevicesKexAlgorithmsKnownHostsCommandLocalCommandLocalForwardLogLevelLogVerboseMACsNoHostAuthenticationForLocalhostNumberOfPasswordPromptsObscureKeystrokeTimingPKCS11ProviderPasswordAuthenticationPermitLocalCommandPermitRemoteOpenPortPreferredAuthenticationsProxyCommandProxyJumpProxyUseFdpassPubkeyAcceptedAlgorithmsPubkeyAuthenticationRekeyLimitRemoteCommandRemoteForwardRequestTTYRequiredRSASizeRevokedHostKeysSecurityKeyProviderSendEnvServerAliveCountMaxServerAliveIntervalSessionTypeSetEnvStdinNullStreamLocalBindMaskStreamLocalBindUnlinkStrictHostKeyCheckingSyslogFacilityTCPKeepAliveTagTunnelTunnelDeviceUpdateHostKeysUserUserKnownHostsFileVerifyHostKeyDNSVisualHostKeyXAuthLocation
โจ 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โ quitsftp๐cd [path]โ changes the remote directory topath. If you don't give apath, it sends you back to the directory your session started in ๐chgrp [-h] grp pathโ changes the group of the file atpathtogrp.pathcan useglob(7)characters and hit multiple files at once ๐ฏgrphas to be a numeric GID, bestie.- If you pass the
-hflag, symlinks won't be followed. โ๏ธโ๐ฅ This only works on servers that implement the"lsetstat@openssh.com"extension, so check your server first ๐
- If you pass the
chmod [-h] mode pathโ changes the permissions of the file atpathtomode.pathcan useglob(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 ๐
- Same deal with
chown [-h] own pathโ changes the owner of the file atpathtoown.pathcan useglob(7)characters and match multiple files ๐งownhas to be a numeric UID.-hmeans symlinks aren't followed, and yep, it only works on servers with the"lsetstat@openssh.com"extension ๐ซ
copy oldpath newpathโ copies a remote file fromoldpathtonewpath๐โจ- This one is only supported by servers that implement the
"copy-data"extension, so it's not guaranteed everywhere ๐
- This one is only supported by servers that implement the
cp oldpath newpathโ an alias for thecopycommand, so it does the exact same thing ๐ฏdf [-hi] [path]โ shows usage info for the filesystem holding the current directory, orpathif you give one ๐พ-hshows the capacity info with "human-readable" suffixes, so you get nice big-unit numbers instead of a wall of digits ๐-iadds 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โ quitsftp๐ (same asbye, literally)get [-afpR] remote-path [local-path]โ downloadsremote-pathand saves it on your local machine ๐ฅ If you don't name alocal-path, it keeps the same name it had on the remote machine.remote-pathcan useglob(7)characters and match multiple files. If it does match multiple files and you give alocal-path, then thatlocal-pathhas to be a directory ๐-atries 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.-ftellssftpto callfsync(2)once the transfer finishes, which flushes the file out to disk ๐ง-pcopies over the full file permissions and access times too ๐โฐ-Rcopies directories recursively ๐ณsftpdoes 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 topath. If you don't give apath, it takes you to the local user's home directory ๐กlls [ls-options [path]]โ displays a local directory listing ofpath, or of the current directory if you skippath๐ls-optionscan be any flags your local system'sls(1)command supports.pathcan useglob(7)characters and match multiple files ๐lmkdir pathโ creates a local directory atpath๐ ๏ธln [-s] oldpath newpathโ creates a link fromoldpathtonewpath๐ 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 ofpath, or the current directory if you don't give one ๐๏ธpathcan useglob(7)characters and match multiple files. These flags are recognized and change howlsbehaves:-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 toumask๐ญmkdir pathโ creates a remote directory atpath๐ธprogressโ toggles the progress meter on or off ๐put [-afpR] local-path [remote-path]โ uploadslocal-pathand stores it on the remote machine โ๏ธ If you don't give aremote-path, it keeps the same name it had locally.local-pathcan useglob(7)characters and match multiple files. If it does and you give aremote-path, thenremote-pathhas to be a directory ๐-atries 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. ๐-fsends a request to the server to callfsync(2)after the file has been transferred. This only works on servers that implement the"fsync@openssh.com"extension ๐ง-pcopies over full file permissions and access times too ๐โฐ-Rcopies directories recursively ๐ณsftpdoes not follow symbolic links during recursive transfers, same as withget๐ฆ
pwdโ displays the remote working directory ๐quitโ quitsftp๐ (yep, another one that does the same thing)reget [-fpR] remote-path [local-path]โ resumes the download ofremote-path. It's equivalent togetwith the-aflag set ๐reput [-fpR] local-path [remote-path]โ resumes the upload oflocal-path. It's equivalent toputwith the-aflag set ๐rename oldpath newpathโ renames a remote file fromoldpathtonewpathโ๏ธrm pathโ deletes the remote file atpath๐๏ธrmdir pathโ removes the remote directory atpath๐ซงsymlink oldpath newpathโ creates a symbolic link fromoldpathtonewpath๐versionโ displays thesftpprotocol version ๐ข!commandโ runscommandin your local shell ๐!โ escapes to your local shell ๐โโ๏ธ?โ a synonym forhelp๐โโ๏ธ
โจ 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
- alpine 3.22: openssh-doc 10.0_p1-r10 ยท SSH-OpenSSH
- alpine 3.23: openssh-doc 10.2_p1-r0 ยท SSH-OpenSSH
- alpine 3.24: openssh-doc 10.3_p1-r1 ยท SSH-OpenSSH
- debian trixie: openssh-client 1:10.0p1-7+deb13u2 ยท OpenSSH
- debian trixie: openssh-client 1:10.0p1-7+deb13u4 ยท OpenSSH
- fedora 43: openssh-clients 10.0p1-12.fc43
- fedora 43: openssh-clients 10.0p1-14.fc43 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND snprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- fedora 43: openssh-clients 10.0p1-5.fc43 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND sprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- fedora 44: openssh-clients 10.2p1-14.fc44
- fedora 44: openssh-clients 10.2p1-16.fc44 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND snprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- fedora 44: openssh-clients 10.2p1-7.fc44 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND snprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixos 26.05: openssh-with-gssapi 10.4p1
- nixpkgs unstable: openssh-with-gssapi 10.4p1
- ubuntu questing: openssh-client 1:10.0p1-5ubuntu5
- ubuntu questing: openssh-client 1:10.0p1-5ubuntu5.4 ยท OpenSSH
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3 ยท OpenSSH
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.6
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.7
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.8 ยท OpenSSH
- ubuntu stonking: openssh-client 1:10.5p1-1ubuntu2
- ubuntu stonking: openssh-client 1:10.5p1-1ubuntu3.1
- ubuntu stonking: openssh-client-gssapi 1:10.5p1-1ubuntu3 ยท OpenSSH
- ubuntu stonking: openssh-client-gssapi 1:10.5p1-1ubuntu3.1 ยท OpenSSH
- Copyright (c) 2001 Damien Miller. All rights reserved
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms