SFTP, otherwise known as SSH File Transfer Protocol, is a secure file transfer protocol similar to FTP, except it’s more secure as the file transfer happens over an encrypted SSH connection.
So while you get all the functionality of FTP, you also get the security of SSH. In this article, we will take a look at what is SFTP and how you can transfer files using the protocol.
What is SFTP?
Aforementioned, SFTP is simply a file transfer protocol that works over an encrypted SSH connection. Unlike SCP, you can do a lot more with SFTP than just transfer files. The protocol allows for a bunch of directory and file manipulation abilities as well.
Since SFTP is a subsystem of SSH, it supports all SSH authentication mechanisms as well. To open a connection to a remote system, use the sftp command followed by the remove server username and the IP address, just like you when establishing an SSH connection.
sftp [email protected]_IP_address
If the host is password authenticated, you’ll be prompted to enter the password as well. Once connected, you’ll see the SFTP prompt. This is where you can start typing in commands and interacting with the remote server.
Also read: How to create an FTP connection on Windows?
How to transfer files using SFTP?
Before we start, if you’re working on a desktop machine, you’re much better using off a GUI SFTP client such as FileZilla or WinSCP. These clients are pretty hassle-free to set up and get the job done rather easily.
However, if you’re in a command-line environment, the SFTP tool becomes your only option.
Downloading files with SFTP
Use the get command to download files from an SFTP server.
You can download multiple files at the same time by listing them one after another.
get file1.zip file2.zip file3.txt
To download directories, use the -r flag to start a recursive directory.
get -r directory1
In case a download failed or was interrupted, you can resume it using the reget command.
Uploading files to an SFTP server
To upload files via SFTP, we’ll be using the put command.
By default, put uploads the files from your current working directory. If the file you want to upload isn’t in the directory you’re running the terminal from; you’re going to have to give the absolute path to the file you want to upload.
The same flags and options apply to put that apply to get. For example, to upload a directory, use the following command.
put -r directory1
Or to resume a failed or interrupted upload
File manipulation with SFTP
In addition to uploading files, you can run a bunch of file manipulation commands such as df, mkdir, rename, rm, rmdir, chmod and chown on the remote server.
You can use standard Linux commands such as cd or ls as well. Once you’re done performing your operations on the server, you can close the connection by typing bye or quit.
Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars. You can reach out to Yadullah at [email protected], or follow him on Instagram or Twitter.