SYNOPSIS
sftp
[
sftp [[user@]host[:file [file]]]
sftp [[user@]host[:dir[/]]]
DESCRIPTION
sftp is a file transfer program, similar to ftp, which performs all operations over an encrypted secsh transport. It may also use many features of ssh, such as public key authentication and compression.
The destination may be specified either as [user@]host[:path] or as a URI in the form sftp://[user@]host[:port][/path].
If the destination includes a path and it is not a directory, sftp will retrieve files automatically if a non-interactive authentication method is used; otherwise it will do so after successful interactive authentication.
If no path is specified, or if the path is a directory, sftp will log in to the specified host and enter interactive command mode, changing to the remote directory if one was specified. An optional trailing slash can be used to force the path to be interpreted as a directory.
Since the destination formats use colon characters to delimit host names from path names or port numbers, IPv6 addresses must be enclosed in square brackets to avoid ambiguity.
Options
-4 -
Forces sftp to use IPv4 addresses only.
-6 -
Forces sftp to use IPv6 addresses only.
-A -
Allows forwarding of ssh-agent to the remote system. The default is not to forward an authentication agent.
-a -
Attempt to continue interrupted transfers rather than overwriting existing partial or complete copies of files. If the partial contents differ from those being transferred, then the resultant file is likely to be corrupt.
-B buffer_size-
Specify the size of the buffer that sftp uses when transferring files. Larger buffers require fewer round trips at the cost of higher memory consumption. The default is 32768 bytes.
-b batchfile-
Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction, it should be used in conjunction with non-interactive authentication to obviate the need to enter a password at connection time (see secshd and secsh-keygen for details).
A batchfile of - may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, reget, reput, rename, ln, rm, mkdir, chdir, ls, lchdir, copy, cp, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir.
Termination on error can be suppressed on a command by command basis by prefixing the command with a - character (for example, -rm /tmp/blah*). Echo of the command may be suppressed by prefixing the command with a @ character. These two prefixes may be combined in any order, for example -@ls /bsd.
-C -
Enables compression (via ssh's
-C flag). -c cipher-
Selects the cipher to use for encrypting the data transfers. This option is directly passed to secsh.
-D sftp_server_command-
Connect directly to a local sftp server (rather than via secsh). A command and arguments may be specified, for example /path/sftp-server -el debug3. This option may be useful in debugging the client and server.
-F ssh_config-
Specifies an alternative per-user configuration file for secsh. This option is directly passed to secsh.
-f -
Requests that files be flushed to disk immediately after transfer. When uploading files, this feature is only enabled if the server implements the fsync@openssh.com extension.
-i identity_file-
Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to secsh.
-J destination-
Connect to the target host by first making an sftp connection to the jump host described by destination and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive. This option is directly passed to secsh.
-l limit-
Limits the used bandwidth, specified in Kbit/s.
-N -
Disables quiet mode, e.g. to override the implicit quiet mode set by the
-b flag. -o ssh_option-
Can be used to pass options to ssh in the format used in secsh_config. This is useful for specifying options for which there is no separate sftp command-line flag. For example, to specify an alternate port use: sftp -oPort=24. For full details of the options listed below, and their possible values, see secsh_config.
AddressFamily BatchMode BindAddress BindInterface CanonicalDomains CanonicalizeFallbackLocal CanonicalizeHostname CanonicalizeMaxDots CanonicalizePermittedCNAMEs CASignatureAlgorithms CertificateFile CheckHostIP Ciphers Compression ConnectionAttempts ConnectTimeout ControlMaster ControlPath ControlPersist GlobalKnownHostsFile GSSAPIAuthentication GSSAPIDelegateCredentials HashKnownHosts Host HostbasedAcceptedAlgorithms HostbasedAuthentication HostKeyAlgorithms HostKeyAlias Hostname IdentitiesOnly IdentityAgent IdentityFile IPQoS KbdInteractiveAuthentication KbdInteractiveDevices KexAlgorithms KnownHostsCommand LogLevel MACs NoHostAuthenticationForLocalhost NumberOfPasswordPrompts PasswordAuthentication PKCS11Provider Port PreferredAuthentications ProxyCommand ProxyJump PubkeyAcceptedAlgorithms PubkeyAuthentication RekeyLimit RequiredRSASize SendEnv ServerAliveInterval ServerAliveCountMax SetEnv StrictHostKeyChecking TCPKeepAlive UpdateHostKeys User UserKnownHostsFile VerifyHostKeyDNS
-P port-
Specifies the port to connect to on the remote host.
-p -
Preserves modification times, access times, and modes from the original files transferred.
-q -
Quiet mode: disables the progress meter as well as warning and diagnostic messages from secsh.
-R num_requests-
Specify how many requests may be outstanding at any one time. Increasing this may slightly improve file transfer speed but will increase memory usage. The default is 64 outstanding requests.
-r -
Recursively copy entire directories when uploading and downloading. Note that sftp does not follow symbolic links encountered in the tree traversal.
-S program-
Name of the program to use for the encrypted connection. The program must understand secsh options.
-s subsystem | sftp_server-
Specifies the SSH2 subsystem or the path for an sftp server on the remote host. A path is useful when the remote secshd does not have an sftp subsystem configured.
-v -
Raise logging level. This option is also passed to ssh.
-X sftp_option-
Specify an option that controls aspects of SFTP protocol behaviour. The valid options are:
- nrequests=value
-
Controls how many concurrent SFTP read or write requests may be in progress at any point in time during a download or upload. By default 64 requests may be active concurrently.
- buffer=value
-
Controls the maximum buffer size for a single SFTP read/write operation used during download or upload. By default a 32KB buffer is used.
Interactive Commands
Once in interactive mode, sftp understands a set of commands similar to those of ftp. Commands are case insensitive and path names may be enclosed in quotes if they contain spaces.
- bye
-
Quits sftp
- cd path
-
Changes remote directory to path. If path is not specified, then change directory to the one the session started in.
- lcd path
-
Changes local directory to path. If path is not specified, then change directory to the local user's home directory.
- chgrp grp path
-
Changes group of file path to grp. path may contain glob characters and may match multiple files. grp must be a numeric GID.
If the
-h flag is specified, then symlinks will not be followed. Note that this is only supported by servers that implement the lsetstat@openssh.com extension. - chmod mode path
-
Changes permission of file path to mode. path may contain glob characters and may match multiple files.
If the
-h flag is specified, then symlinks will not be followed. Note that this is only supported by servers that implement the lsetstat@openssh.com extension. - chown own path
-
Changes owner of file path to own. path may contain glob characters and may match multiple files. own must be a numeric UID.
If the
-h flag is specified, then symlinks will not be followed. Note that this is only supported by servers that implement the lsetstat@openssh.com extension. - copy oldpath newpath
-
Copy remote file from oldpath to newpath.
Note that this is only supported by servers that implement the copy-data extension.
- cp oldpath newpath
-
Alias to copy command.
- df [
-hi ] [path] -
Displays usage information for the file system holding the current directory (or path if specified). When the
-h flag is specified, the capacity information is displayed using "human-readable" suffixes. The-i flag requests display of inode information in addition to capacity information. This command is only supported on servers that implement the statvfs@openssh.com extension. - exit
-
Quits sftp.
- get [flags] remote-path [loacl-path]
-
Retrieves the remote-path and stores it on the local machine. If the local path name is not specified, it is given the same name it has on the remote machine. remote-path may contain glob characters and may match multiple files. if it does, and local-path is specified, then local-path must specify a directory.
If either the
-P or-p flag is specified, then full file permissions and access times are copied too.If the
-r flag is specified then directories will be copied recursively. Note that sftp does not follow symbolic links when performing recursive transfers.If the
-a flag is specified, then attempt to resume partial transfers of existing files. Note that resumption assumes that any partial copy of the local file matches the remote copy. If the remote file contents differ from the partial local copy then the resultant file is likely to be corrupt.If the
-f flag is specified, thenfsync() will be called after the file transfer has completed to flush the file to disk.If the
-p flag is specified, then full file permissions and access times are copied too.If the
-R flag is specified then directories will be copied recursively. Note that sftp does not follow symbolic links when performing recursive transfers. - help
-
Displays help text.
- lls [ls-options] [path]]
-
Displays local directory listing of either path or current directory if path is not specified. ls-options may contain any flags supported by the local system's ls command. path may contains glob characters, and may match multiple files.
- lmkdir path
-
Creates local directory specified by path.
- ln [
-s ] oldpath newpath -
Creates a link from oldpath to newpath. If the -s flag is specified the created link is a symbolic link, otherwise it is a hard link.
- lpwd
-
Displays local working directory.
- ls [flags] [path]
-
Displays remote directory listing of either path or current directory if path is not specified. path may contain glob characters and may match multiple files.
The following flags are recognized and alter the behavior of ls accordingly:
-1 -
Produces single column output.
-a -
Lists files beginning with a dot (.).
-f -
Does not sort the listing. This default sort is lexicographical.
-h -
When used with a long format option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, and Exabyte in order to reduce the number of digits to four or fewer using powers of 2 for sizes (K=1024, M=1048576, etc.).
-l -
Displays additional details including permissions and ownership information.
-n -
Produces a long listing with user and group information presented numerically.
-r -
Reserves the sort order of the listing.
-S -
Sorts the listing by file size.
-t -
Sorts the listing by last modification time.
- lumask umask
-
Sets local umask to umask.
- mkdir path
-
Creates remote directory specified by path.
- put [flags] local-path [local-path]
-
Uploads local-path and stores it on the remote machine. If the remote path name is not specified, it is given the same name it has on the local machine. local-path may contain glob characters and may match multiple files. If it does and remote-path is specified, then remote-path must specify a directory. If the
-P flag is specified, then the file's full permission and access time are copied too.If either the -P or -p flag is specified, then full file permissions and access times are copied too.
If the -r flag is specified then directories will be copied recursively. Note that sftp does not follow symbolic links when performing recursive transfers.If the
-a flag is specified, then attempt to resume partial transfers of existing files. Note that resumption assumes that any partial copy of the remote file matches the local copy. If the local file contents differ from the remote local copy then the resultant file is likely to be corrupt.If the
-f flag is specified, then a request will be sent to the server to callfsync() after the file has been transferred. Note that this is only supported by servers that implement the fsync@openssh.com extension.If the
-p flag is specified, then full file permissions and access times are copied too.If the
-R flag is specified then directories will be copied recursively. Note that sftp does not follow symbolic links when performing recursive transfers. - progress
-
Toggles display of progress meter.
- pwd
-
Displays remote working directory.
- quit
-
Quits sftp.
- reget [flags] remote-path [local-path]
-
Resume download of remote-path. Equivalent to get with the
-a set. - rename oldpath newpath
-
Renames remote file from oldpath to newpath.
- reput [flags] local-path [remote-path]
-
Resume upload of local-path. Equivalent to put with the
-a flag set. - rmdir path
-
Removes remote directory specified by path.
- rm path
-
Deletes remote file specified by path.
- symlink oldpath newpath
-
Create a symbolic link from oldpath to newpath.
- version
-
Displays sftp protocol version.
- ! command
-
Executes command in local shell.
- !
-
Escapes to local shell.
- ?
-
Synonym for help.
AUTHORS
Damien Miller <djm@mindrot.org>
PORTABILITY
All UNIX systems. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. Windows Server 2025.
NOTES
There is no binary/text file transfer mode. All files are transferred in binary mode.
There is no file globbing capability. Thus, ls *.tar will not succeed, unless of course you are a sick and twisted individual who names files *.tar.
AVAILABILITY
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Commands:
- scp, secsh, secsh-add, secshd, secsh-keygen, secsh-keysign, sftp-server
PTC MKS Toolkit Connectivity Solutions Guide
T. Ylonen and S. Lehtinen, SSH File Transfer Protocol, draft-ietf-secsh- filexfer-00.txt, January 2001, work in progress material.
PTC MKS Toolkit 10.5 Documentation Build 40.