Using sFTP in Linux and Windows

Using sFTP SSH File Transfer Protocol

It all started with the unencripted File Transfer Protocol. It was used (and still is) for transferring unencripted data between two remote host via the Internet. In my previous post I covered the topic of using the VsFTP with the cryptographic protocol TLS (Transport Layer Security) to provide communications security over a computer network.

Using sFTP to transfer files between Internet hosts
Using sFTP to transfer files between Internet hosts

sFTP, unlike FTPs, is a separate protocol, that runs on top of SSH. It comes pre-packaged with SSH and supports all of its authentication and security features. sFTP has replaced both FTP and FTPs and is now the most popular method for secure file transfer between a host and a server. No more un- encrypted passwords and data over the internet.

SFTP Servers for Linux & Windows

If you have OpenSSH installed on your Linux host, the chances are, you have already a sFTP server installed. If you use Windows, you can give Filezilla Server a try. It is completely free, and there is already a large FileZilla community to ask your questions.

sFTP Clients for Linux & Windows

The most commonly used client for Linux is the command sftp. If you type in a terminal window man sftp, it will display the manual of the command with the full synopsis.

$ man sftp

sFTP commands operates just like the well- known ftp command, with only difference using SSH as a transport layer. Hence its default port would be 22. Also, sFTP supports an identity file, which it passes to SSH. By default it looks at the .ssh folder of the home directory of the user.

Being a fusion command between both, sftp functions like ssh during the authentication phase, and then like ftp command, once you are logged in the server.

$ sftp myuser@myserver
sftp has the same set of commands as ftp
sftp has the same set of commands as ftp

Moreover, if you are using an identity file with a private key, you can also pass it to the command by:

sftp -i identity_file -P remote_host_port myuser@myserver

Using sFTP command

sFTP is using as a regular FTP command. Type in help or ? to get a complete list of the commands. pwd will show you the current remote directory. ls will list the current directory. Here is a well known ls -la

sftp> ls -la
drwxr-xr-x    6 user   user       4096 Aug 28 02:31 .
drwxr-xr-x    5 root   root     4096 Aug 17 00:33 ..
-rw-------    1 user   user       2428 Apr  5 03:07 .bash_history
-rw-r--r--    1 user   user        220 Oct  7  2020 .bash_logout
-rw-r--r--    1 user   user       3771 Oct  7  2020 .bashrc
drwx------    2 user   user       4096 Oct  7  2020 .cache
sftp> 

Transferring Files Using sFTP

Downloading files from the remote server is easier than ever. The following code will download the remote_file to the current directory.

sftp> get remote_file

Moreover, uploading files to the remote server or host is almost as easy.

sftp> put local_file

Using scp to transfer files

Scp is another option when it comes to simple file transfer. It requires SSH server in order to work. Its general usage is given below:

$ scp [OPTIONS] [SOURCE] [DESTINATION]

If you would like to copy a local file to a remote server/directory, the usage would be:

scp local_file remote_user@remote_host:directory/remote_file

Whereas, if you need to copy a remote file to a local directory, the syntax would be:

scp local_file remote_user@remote_host:directory/remote_file

Last Words Using sFTP

Using sFTP is easy and straightforward. You don’t have to learn new options and synopsis for using it. The chances are, you already have experience with the old- time FTP. Simple, yet powerful, sFTP has details and bugs on its own. Nevertheless, it is one of the best tools when it comes to secure transfers between two internet hosts.

Leave a Reply

Your email address will not be published. Required fields are marked *