Secure File Transfer Protocol (or SFTP, and also known as SSH File Transfer Protocol), is an extension of SSH that provides encrypted file transfer capabilities. Since it is built into SSH, it is one of the easiest ways to transfer files between system, as in many cases you won't have to configure additional software to use it.
SFTP is a widely-supported protocol, so you can use it in a variety of applications. For Linux, BSD & MacOS users, your local shell is by far the quickest way to transfer files using SFTP:
Connecting to an SFTP server works exactly the same as connecting to an SSH server - you just use the sftp
instead of the ssh
command, and when prompted give your password:
$ sftp username@domain.com or $ sftp username@123.123.123.123
Since SFTP is part of SSH, that means the preset aliases in your .ssh/config
file will all work with the sftp
command. If you have not created one of these files, you will want to, as it enables automatically passing public/private key pairs for convenient password-less authentication. Read SSH Configuration for more information on how to do this.
Traversing an SFTP system works much the same way as it does in bash - in fact it uses simplified versions of many of the same commands, albeit in a reduced form.
Use pwd
to show your current location (the 'present working directory') on the remote server:
sftp> pwd
Use the ls
command to show the contents of the pwd. Use ls -la
to show a more detailed listing with metadata:
sftp> ls sftp> ls -la
Use the cd
command to change the pwd:
sftp> cd path/to/directory/
Before downloading anything, check the download path (or the 'local pwd') with the lpwd
command, so you know where your files are going:
sftp> lpwd
If you are not happy with this path, use the lcd
command (like cd
above) to change it. Likewise, use lls
to list the contents of your local pwd.
sftp> lcd new/path/ sftp> lls -la
Once you know where your downloads are going, you can grab files with the get
command:
sftp> get filename
To download whole directories, use the -r
flag:
sftp> get -r name/of/directory/
This section needs expansion. You can help by adding to it.
This section needs expansion. You can help by adding to it.
For unfortunate Windows users with PowerShell, you do not have SFTP support built-in. You will have to set up Posh-SSH to use SFTP from your shell with your local filesystem.