The sftp client is an alternative to scp, though under the hood it does mostly the same thing: it copies files between SSH client and server machines securely. The main difference is that sftp is interactive, with an interface much like the old FTP programs. [2.7.1]
To get started, run sftp with a remote hostname:
$ sftp server.example.com
or username and hostname:
$ sftp smith@server.example.com
You'll get a prompt:
sftp>
and now may type commands to transfer files between your local and remote machine. For example:
sftp> cd remote_directory Change to a particular remote directory sftp> ls List the names of available files sftp> get remotefile Download the file "remotefile" sftp> get remotefile newname Same as above, but the local file will be renamed as "newname" sftp> put localfile Upload the file "localfile" sftp> put localfile othername Same as above, but the remote file will be renamed as "othername" sftp> quit Quit sftp
The basic use of sftp will feel familiar to anyone who's used an FTP program. Use the cd command to move around the remote filesystem (or lcd for the local filesystem), ls to list the available remote files, and the get and put commands to download and upload files, respectively. Table 7-4 lists the interactive commands available during an sftp connection.
Table 7-4. Interactive commands for sftp, grouped by function
Command | Meaning | Support |
---|---|---|
a Not needed unless you run Tectia sftp with no arguments, so no initial connection is established. | ||
b On Tectia,
| ||
Basic commands | ||
open | Open a connection to the remote machine a | Tectia |
lopen | Open a connection to the local machine a | Tectia |
close | Close the connection to the remote machine | Tectia |
lclose | Close the connection to the local machine | Tectia |
bye, quit | Quit sftp | OpenSSH, Tectia |
exit | Quit sftp | OpenSSH |
help | Print a help message | OpenSSH, Tectia |
? | Print a help message | OpenSSH |
version | Display the SFTP protocol version | OpenSSH |
! | Shell escape: execute a local shell or command | OpenSSH |
Directory commands | ||
ls | List files in a remote directory | OpenSSH, Tectia |
lls | List files in a local directory | OpenSSH, Tectia |
cd | Change the remote working directory | OpenSSH, Tectia |
lcd | Change the local working directory | OpenSSH, Tectia |
pwd | Print the name of the remote working directory | OpenSSH, Tectia |
lpwd | Print the name of the local working directory | OpenSSH, Tectia |
mkdir | Create a remote directory | OpenSSH, Tectia |
lmkdir | Create a local directory | OpenSSH, Tectia |
rmdir | Delete a remote directory | OpenSSH, Tectia |
lrmdir | Delete a local directory | Tectia |
lsroots | List virtual roots of a VShell SSH server [17.9] | Tectia |
File commands | ||
get | Download a file from the remote machine | OpenSSH, Tectia b |
mget | Download multiple files by wildcard | OpenSSH, Tectia b |
put | Upload a file to the remote machine | OpenSSH, Tectia b |
mput | Upload multiple files to the remote machine | OpenSSH, Tectia b |
rename | Rename a remote file | OpenSSH, Tectia |
lrename | Rename a local file | Tectia |
ln, symlink | Create a symbolic link on the remote machine | OpenSSH |
rm | Delete a remote file | OpenSSH, Tectia |
lrm | Delete a local file | Tectia |
chmod | Change the permissions on a remote file | OpenSSH, Tectia |
lchmod | Change the permissions on the local file | Tectia |
chown | Change the owner of a remote file | OpenSSH |
chgrp | Change the group ownership of a remote file | OpenSSH |
Transfer settings | ||
binary | Transfer all files as binary | Tectia |
ascii | Transfer all files as ASCII | Tectia |
auto | Determine the file type using the "setext" list | Tectia |
getext | Print the list of file extensions that indicate text files | Tectia |
setext | Set the list of file extensions that indicate text files | Tectia |
lumask | Set the umask for downloaded files | OpenSSH |
progress | Toggle the display of a progress meter for file transfers | OpenSSH |
Virtually all command-line options available to scp will work for sftp. [7.5]