What is the SSH File Transfer Protocol (SFTP)

What is the SSH File Transfer Protocol (SFTP)

14.05.2024
Author: HostZealot Team
2 min.
202

The security of the transfer protocol has always been an important topic for a variety of users. That’s why older protocols such as FTPS and FTP are not as popular as the more modern option – SFTP. SSH File Transfer Protocol is an awesome variant that has a variety of features and is based on SSH.

Here in the article, we will go deeper with SFTP understanding and share a couple of good recommendations for checking the storage space. Also, we will discuss a couple of useful SFTP commands.

SSH and SFTP Overview

To get a general understanding of the major characteristics of SFTP. Let’s discuss some crucial elements that stand out this protocol from others and they are such as the security of the data, file management for remote and local systems, key authentication, directory browsing on the server and client side, and also compatibility with most operating systems. If talking specifically about the security of the data transfer, then SFTP functioning relies on the SSH protocol for encryption and additional protection.  

In case of proper authentication and authorization, SSH permits any type of needed command in the shell.

At the same time when talking specifically about SFTP, it has a rather limited number of available commands that are obviously connected with the file transfer. SFTP is more restricted to the SSH than other protocols so it should not be considered fully separate.

The SSH Subsystem Mechanism

The subsystem can run on the SSH protocol as an abstraction layer. Let’s practically explain how we can do it with the creation of executables.  

Creation of Executables for Subsystems

Let’s start with the simple script and place it in /usr/lib/openssh/:

$ cat /usr/lib/openssh/xid.sh
#!/usr/bin/env bash
hostname
$ chmod +x /usr/lib/openssh/xid.sh

Subsystem Setup

For the configuration of the system, let’s utilize /etc/ssh/sshd_config. Here we are setting xid as a subsystem:

$ cat /etc/ssh/sshd_config
[...]
# override default of no subsystems
Subsystem  xid  /usr/lib/openssh/xid.sh
[...]

SFTP Setup

Let’s make it clear, but SFTP servers are also considered to be subsystem of SSH. In addition to this, ssh and sftp clients are almost equivalent when using -s sftp:

$ ssh [...] -s sftp

SFTP Command Overview

Depending on the SFTP implementation of the server, there are some parts that are restricted to pure SSH and others that are SFTP. This means some are integrated into sshd, and at the same time, others are separate such as sftp-server.

Basic Commands for Everyday Use

To review all the most basic commands that are supported by SFTP, you can use help. By typing help in the sftp prompt, the list will appear with the most essential points about the file transfer, removal, and way more.

Here are a couple of samples for you to test out:

  • chmod [-h] mode path – modify the permissions of file 'path' to 'mode'
  • version – review the current SFTP version
  • ? – this command can be used instead of help, and you will get the same output                            
  • chown [-h] own path – modify the owner of the file 'path' to 'own'         
  • bye – stop SFTP  
  • cd path - modify remote direct to 'path'
  • chgrp [-h] grp path - modify the group of file
  • !command - do a specific command that you insert after '!' in the local shell

Updates and Extensions in SFTP Functionality

The specifications of SFTP are available in various versions already, starting from the 3rd and ending with the 6th. However, as a rule, only the default or the 3rd version is supported by OpenSSH and some other SSH servers.

Of course, it is not a problem and you can easily replace this default version with the preferred one, but in some scenarios, the functioning of SSH and other versions may be inconsistent. From another perspective, version 3 can properly facilitate any necessary code so that is not a problem at all.  

Proprietary Commands for Specialized Tasks

Because this type of protocol functions on SSH servers, all the commands should be executed via ssh. For instance, to check the available storage of the server, use the following command:

$ ssh jane@145.123.5.55 df

Storage Checks in SFTP Environment

Storage Checks in SFTP Environment are extremely important for a variety of reasons, but somehow such checks are not included in the initial version of this protocol.

For this reason, you can use statvfs implementation for the checks. So, utilize df command in such a way:

sftp > df -h

When talking about the 6th version of SFTP, then users can check the storage right away without the necessity for the previously discussed implementation. Here are several apps that can leverage such functionality:

  • WinSCP
  • ProFTPD
  • Bitvise

The utilization of any type of client-server combination will be enough to contact checks via a certain feature.

Conclusion

Here, we shared a couple of practical recommendations and helpful commands for the SFTP and its proper functioning to SSH. Although not a majority of features in this protocol are implemented in most servers, you can easily try the usage of extensions.

Related Articles