sftp

secure file transfer program 

Command


SYNOPSIS

sftp [-46afpqrvC] [-F ssh_config] [-B buffer_size] [-b batchfile] [-c cipher] [-i identity_file] [-o ssh_option] [-s subsystem|sftp_server] [-P port] [-R num_requests] [-S program] [-o ssh_option] [host]

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 secsh, such as public key authentication and compression. 2

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 

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.

-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.

-B buffer_size 

Specifies the size of the buffers 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, 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*).

-C 

Enables compression (via secsh'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_path 

Connect directly to a local sftp server (rather than via secsh). 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.

-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.

-o ssh_option 

Any valid -o option to secsh can be specified, and it is directly passed through when secsh is invoked. This is useful for specifying options for which there is no separate sftp command-line flag. For example, to specify an alternate port:

sftp -oPort=24
-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 

Specifies how many requests may be outstanding at any one time. Increasing this may slightly improve file transfer speed but increases 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 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.

-S program 

Specifies the name of the program to use for the encrypted connection. The program must understand secsh options.

-v 

Raises logging level. This option is also passed to secsh.

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.

chmod mode path 

Changes permission of file path to mode. path may contain glob characters and may match multiple files.

chown own path 

Changes owner of file path to own. own must be a numeric UID.

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, then fsync() will be called after the file transfer has completed to flush the file to disk.

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 call fsync() after the file has been transferred. Note that this is only supported by servers that implement the "fsync@openssh.com" extension.

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 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


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.4 Documentation Build 39.