Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sftp - Secure file transfer between computers in a network

&pagelevel(4)&pagelevel

Syntax

sftp [-1246aCfpqrv] [-B <buffer_size>] [-b <batchfile>] [-c <cipher>] 
    [-D <sftp_server_path>] [-F <ssh_config>] [-i <identity_file>] [-l <limit>]
    [-o <ssh_option>] [-P <port>] [-R <num_requests>] [-S <program>]
    [-s <subsystem> | <sftp_server>] [-X binary] <host>
sftp [-X binary] [[<user>@]<host>[:<file> [<file>]]] 
sftp [-X binary] [[<user>@]<host>[:<dir>[/]]] 
sftp [-X binary] -b <batchfile> [<user>@]<host> 

A detailed description of the operands is provided in the OpenSSH man pages.

Description

sftp is an interactive program for file transfer (like FTP) which handles all operations at TCP level via an encrypted ssh channel. In addition, sftp can utilize many features of ssh such as public key authentication and data compression. sftp establishes the connection to the specified computer and logs on there. Afterward sftp is in interactive mode for command input.

The -X binary option can be used for connections to ASCII servers in order to transfer files in binary format (bit-identical). In interactive mode the type [text|binary] command (see "sftp - Secure file transfer between computers in a network") can also be used for this purpose. For connections to EBCDIC servers, this option must be omitted in order to get a bit-identical transfer.

Transferring files from a remote directory

The command format

sftp [-X binary] [[<user>@]<host>[:<file> [<file>]]]

enables you to use sftp to transfer files automatically from a directory on a remote computer to the local directory. A prerequisite for this is that non-interactive authentication is used, otherwise file transfer is only possible after successful interactive authentication.

Starting sftp in a remote directory

The following command format enables you to start sftp in a directory on a remote computer:

sftp [-X binary] [[<user>@]<host>[:<dir>[/]]]

Automated sftp sessions

The command format

sftp [-X binary] -b <batchfile> [<user>@]<host>

permits automatic sftp sessions using the -b option. In this case public key authentication is generally required to bypass the need to enter a password for connection setup (see the section “Authentication between OpenSSH client ssh and server sshd”).

Interactive commands

In interactive mode sftp provides you with a number of interactive commands which are similar to those of FTP.

The following must be borne in mind for the command notation:

  • It is not case-sensitive.

  • Path names containing blanks must be enclosed in single or double quotes.

bye

Terminates sftp.

cd <path>

Changes the directory on the remote computer in <path>.

chgrp <group> <path>

Changes the group ID of the <path> file in <group>.
<group> must be a numerical group ID.

chmod <mode> <path>

Changes access rights of the <path> file on <mode>.

chown <own> <path>

Changes owner of the <path> file to <own>. <own> must be a numerical UID.

exit

Exits sftp.

get [<flags>] <remote-path> [<local-path>]

Transfers the <remote-path> file from the remote computer to the local computer and stores it under <local-path>. If <local-path> is not specified, the file is stored under the same name as on the remote computer.
If the -P flag is specified, all access rights and the time the file was accessed are also copied.

help

Displays help text (brief reference material for the commands).

lcd <path>

Changes local directory in <path>.

lls [<ls-options> [<path>]]

Displays local directory. Either displays <path> or, if <path> is not specified, displays the current directory.

lmkdir <path>

Creates the local directory specified by <path>.

ln <oldpath> <newpath>

Creates symbolic link from <oldpath> to <newpath>.

lpwd

Displays local working directory.

ls [<flags>] [<path>]

Displays the contents of the remote directory. Displays either contents of <path> or, if <path> is not specified, displays the contents of the current directory. If the -I flag is not specified, displays additional information, including permissions and ownership.

lumask <mask>

Changes local umask (access rights) to <mask>.

mkdir <path>

Creates remote directory specified by <path>.

progress

Enables/disables progress display.

put [<flags>] <local-path> [<remote-path>]

Uploads <local-path> file and transfers it to the remote computer. If <remote-path> is not specified, the file on the remote computer is given the same name as on the local computer. If the -P flag is specified, all the file’s access rights and the time the file was accessed are also copied.

pwd

Displays remote working directory.

quit

Quits sftp.

rename <oldpath> <newpath>

Renames remote file from <oldpath> to <newpath>.

rm <path>

Removes remote file <path>.

rmdir <path>

Removes remote directory <path>.

symlink <oldpath> <newpath>

Creates symbolic link from <oldpath> to <newpath>.

type [binary|text]

Sets transfer mode (for connections to ASCII computers) to “binary” or resets it to “text”. If no argument is specified, the current mode is displayed (see also call option -X binary).

version

Displays protocol version of sftp.

! <command>

Executes command <command> in the local shell.

!

Generates local subshell.

?

Displays help text (brief reference material for the commands) (same as help, see above).