Skip to content

What is SFTP? How to transfer files using SFTP?

  • by
  • 3 min read

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. 

Also read: What port does SFTP use? How to change the SFTP port?

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 remote_username@server_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. 

get filename

You can download multiple files at the same time by listing them one after another. 

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

put file1.txt

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

reput file1.txt

Also read: What is DF? How to check disk space in Linux using DF?

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. 

Also read: How to use SCP command to transfer files in Linux?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: