Home » Wiki » What is SSH File Transfer Protocol (SFTP)

What is SSH File Transfer Protocol (SFTP)

by | SSL Certificate

SSH File Transfer Protocol (SFTP)

What is SSH File Transfer Protocol?

SFTP is a secure network protocol that enables file transfer between computers over an encrypted connection. It was developed as a more secure alternative to the standard FTP protocol. SFTP uses SSH encryption to protect data during transmission, making it difficult for unauthorized users to access sensitive information. The protocol provides file access, transfer, and management functions.

SFTP runs on port 22 by default and requires authentication through passwords or SSH keys. Organizations use SFTP to share confidential files, backup data, and manage remote server content. This protocol ensures data integrity and security during all file operations.

Key Capabilities of SSH File Transfer Protocol (SFTP)

  • Secure remote file access: Browse, view, edit, delete, and rename files on the remote system.
  • Uploading and downloading: Transfer files of any size to and from the server.
  • Directory management: Create, delete, and move folders on the remote filesystem.
  • Permissions management: Set read/write/execute permissions on remote files and directories.
  • Resume capability: Pause and resume file transfers in case of interruptions.
  • Tunneling support: Tunnel SFTP through SSH connections for proxying.

With its strong encryption, rigorous authentication, ease of use, and range of features, SFTP provides an indispensable tool for securely managing files over networks. It is widely deployed for everything from web publishing to system administration.

How SSH File Transfer Protocol (SFTP) Works

SFTP combines the convenience of FTP with the security of the SSH protocol. Rather than invent its own data transportation method, SFTP simply layers its file access and transfer functionality on top of an SSH connection.

This allows it to encrypt all communication using the same symmetric encryption (e.g., AES, Blowfish, etc.) employed in the SSH tunnel. It also benefits from SSH’s strong authentication methods, such as passwords and public keys.

The basic SFTP architecture comprises a client and server:

SFTP Architecture

SFTP Client

This is the user’s interface to access, manage, and transfer files on the remote host. The client software sends file operation commands and data to the server over the secured SSH tunnel.

It tracks the user’s actions locally and sends equivalent SFTP protocol requests to the server, such as requesting to retrieve a file or delete a directory. Many types of clients are available, e.g., standalone apps, IDE integrations, browser plugins, and more.

SFTP Server

This software listens for incoming SFTP requests from clients and performs corresponding actions on the host’s filesystem. Popular servers include OpenSSH, ProFTPD, Microsoft SFTP, etc.

The server controls which SFTP commands the client can execute based on configured security policies. It also logs all SFTP activity. Many servers integrate with SSH servers rather than act as standalone processes.

Why Use SFTP Over FTP?

Although FTP is still used today, it has a number of security weaknesses that make SFTP a better solution in most cases:

  • Encryption: All SFTP traffic is encrypted using secure ciphers negotiated with SSH. FTP transmits everything in plain, unencrypted text.
  • Security: SFTP uses SSH keys, passwords, and other strong auth methods, while FTP relies on weak plaintext user credentials.
  • Integrity checking: Data integrity mechanisms in SSH protect against tampering or forgery of SFTP transfers.
  • Traffic visibility: SFTP tunnels through SSH, avoiding insecure data on external-facing ports needed for passive FTP. This also improves firewall traversal.
  • Authentication: SFTP allows verifying both client and server. FTP typically only authenticates clients.
  • Resume capability: SFTP can resume interrupted transfers. FTP has limited support for resuming file transfers.
  • Scriptable and automatable: SFTP works easily with scripts and automation tools. FTP use requires tricky workarounds.

SFTP Clients

SFTP clients allow securely connecting to remote servers, transferring files back and forth, and managing remote directories and permissions. Many types of SFTP clients are available across different operating systems:

Command Line SFTP Clients

These provide a basic text-based SFTP interface that can be easily used in terminal sessions, automation scripts, and shell programs:

  • OpenSSH: The OpenSSH suite includes the sftp client tool that comes pre-installed on most Linux and macOS systems. It has all core SFTP capabilities exposed through straightforward commands.
  • PuTTY PSFTP: Available for Windows and Linux, PSFTP provides a simple command-line client similar to OpenSSH’s sftp. It has the benefit of tight integration with PuTTY for SSH connections.
  • WinSCP: This popular Windows client has both a GUI and a command-line winscp.com tool. The latter provides scriptable SFTP transfers.

GUI SFTP Clients

These offer more user-friendly graphical access to SFTP capabilities through desktop applications:

  • FileZilla: Available on Windows, Mac, and Linux, FileZilla provides fast and reliable SFTP support alongside FTP in an intuitive interface.
  • WinSCP: As mentioned above, WinSCP has an excellent cross-platform GUI client in addition to its command line tool. Supports advanced SFTP features like SSH keys and port forwarding.
  • CyberDuck: This open-source client for Mac and Windows provides easy graphical SFTP access alongside protocols like FTP and cloud storage services. It has a clean interface and useful connection tools.

IDE SFTP Plugins

Integrated plugin clients allow direct transferring of files between your coding IDE and development servers:

  • SFTP for Visual Studio Code: Simple VS Code extension that provides two-click uploads and downloads between the editor and SFTP sites.
  • Remote Development: Extension pack for VS Code that includes SFTP support along with other remote dev capabilities. More advanced features than the above plugin.
  • IntelliJ Idea SFTP: Plugin for JetBrains IDE that enables direct file transfers and remote server browsing from within Idea. Seamless integration with the editor.

List of SSH File Transfer Protocol (SFTP) Servers

While SFTP clients allow you to transfer files from your system, SFTP servers enable securely hosting files and making them accessible to clients. Popular SFTP server software includes:

Linux SFTP Servers

  • OpenSSH: The OpenSSH daemon sshd implements SFTP server support and is the most common choice on Linux. Already installed on most distros and is easy to configure through sshd_config.
  • ProFTPD: Feature-rich open-source FTP and SFTP server for Linux, BSD, and Unix. Good performance and a modular architecture with a loadable SFTP module.
  • Pure-FTPd: Another alternative FTP/SFTP daemon for Unix-like systems. Known for speed and stability. Needs to be compiled with SFTP support.

Windows SFTP Servers

Microsoft Windows lacks a built-in SFTP server. But many good third-party options exist:

  • Bitvise SSH Server: High performance Windows server supporting SFTP and SCP using the installed OpenSSH binaries. User-friendly interface and advanced security policies.
  • Rebex Tiny SFTP Server: Lightweight server focused just on SFTP. Easy to install and manage. Integrates with Windows accounts and file permissions.
  • SolarWinds SFTP/SCP Server: Part of the Serv-U managed file transfer server suite. Supports automated and scheduled SFTP transfers.

Network Attached Storage (NAS)

Many NAS devices like Synology, QNAP, and Netgear boxes now include optional SFTP access to files on the NAS:

  • Synology SFTP: Available by installing the File Station package on DiskStation. Allows SFTP/SSH connections alongside FTP, SMB, and AFP.
  • QNAP SFTP: Activate SFTP service on Turbo NAS devices in the control panel. Permissions integrate with QNAP user accounts.
  • Netgear ReadyNAS SFTP: Enable the SFTP server in the ReadyNAS admin dashboard to access NAS files securely over SSH.

These are some of the most popular SFTP server implementations across major platforms and devices. Once the server is set up, clients can securely access hosted files.

Using SSH File Transfer Protocol (SFTP) Clients

Once you have an SFTP client installed on your local system and a server set up on the remote host, you can start using SFTP to transfer and manage files securely.

Here are some common SFTP operations to get started:

Connecting to SFTP Server

Initiate an SFTP session by providing the remote server details when prompted by the client. This will establish the encrypted SSH tunnel: sftp username@ftpserver OR sftp -P 2222 username@ftpserver (non-default port)

You’ll need to authenticate, typically by entering the password. With public key authentication, the key passphrase may be requested instead.

Transferring Files

Once connected, you can upload or download files. Common syntax includes:get remote_file local_file (download file) put local_file remote_file (upload file)

Additional options like -r for recursive directory transfer are supported. The exact commands vary across clients but work similarly.

Handling Directories

Navigate directories on the SFTP server like a local filesystem:ls (list directory contents), cd path (change to directory), mkdir (create directory), rmdir (remove directory)

Right click menus in GUI clients also allow managing remote directories through graphical operations like drag and drop.

Closing SFTP Session

When done, close the connection to exit the SFTP session: exit OR quit

This will end the SSH tunnel and log you out of the server.

Using SSH Keys

Instead of passwords, SFTP allows public key authentication for better security. The steps involve:

  • Generate a keypair (public and private key) on the client machine.
  • Copy the public key to the user account on the SFTP server ~/.ssh/authorized_keys.
  • Connect via SFTP and provide the private key when prompted.

This will log you in without the need for passwords. SSH keys offer much stronger security than reusable credentials.

How to Automate SFTP Transfers

A key benefit of SFTP vs FTP is the ability to script and automate file transfers easily. This avoids tedious manual actions for recurring jobs.

Some ways to automate SFTP include:

Cron Jobs (Linux/Unix)

Schedule background SFTP commands using cron, e.g.:“`

m h dom mon dow command

0 5 * * * sftp user@host <<< $’cd /home\n put file.txt’“`

This will upload file.txt daily at 5 AM to the remote user’s home folder.

Batch Scripts (Windows)

Write .bat scripts that call SFTP commands using a client like WinSCP’s winscp.com:winscp.com /command “put c:\localfolder\file.zip /public_html/file.zip” “exit”

Then, schedule the scripts using Windows Task Scheduler.

SFTP Libraries

Code SFTP transfers in Python, Node.js, C#, etc., using libraries like Paramiko (Python), ssh2 (Node.js), and Renci.SshNet (C#). Integrate into apps.

Managed File Transfer

Tools like IBM Sterling, GoAnywhere MFT, and SolarWinds Serv-U provide an automation platform with SFTP support. They handle key management, monitoring, etc.

So, those are some ways to automate recurrent SFTP file transfers without requiring constant manual processes.

Final Thoughts

SSH File Transfer Protocol (SFTP) provides a critical service by enabling secure file transfers over SSH. Its strong encryption, rigorous authentication, ease of use, and widespread availability across clients and servers make it an essential tool for anyone needing to access or transfer files over networks securely.

Following best practices around permissions, keys, and performance tuning ensures robust and optimized SFTP operations. With capabilities for reliable automation and resuming interrupted transfers, SFTP delivers a full-featured yet simple solution for encrypted file management between systems.

For use cases ranging from web publishing to system administration, SFTP checks all the boxes for a secure and managed file transfer protocol.

Frequently Asked Questions (FAQs)

What is the difference between SFTP vs FTP?

The main difference is that SFTP transfers files over an encrypted SSH connection, while standard FTP does not have encryption. This gives SFTP far greater security. Other SFTP advantages include stronger authentication, integrity checking, easier scripting, and firewall traversal.

Is SFTP faster than FTP?

SFTP is generally slower than unencrypted FTP due to the overheads of encryption. But modern systems make the difference negligible for most use cases. SFTP is still very efficient for transferring files while providing security.

What port does SFTP use?

By default, SFTP uses TCP port 22, the standard port for SSH connections. However, this can be changed in the server configuration if needed, for example, to avoid conflicts with another service using port 22.

Is SFTP the same as FTPS?

FTPS is FTP over explicit SSL/TLS encryption. SFTP differs in that it operates over an SSH-encrypted tunnel rather than TLS. SFTP authentication is also based on SSH rather than FTP users and permissions. So, SFTP is better integrated with SSH for a seamless encrypted file transfer solution.

Can FileZilla do SFTP?

Yes, FileZilla is one of the most popular cross-platform SFTP clients. It supports SFTP alongside FTP/FTPS. The SFTP option can be chosen when creating a new site profile in FileZilla.

Can I automate SFTP file transfers?

Absolutely. Automating SFTP is straightforward with cron jobs, batch scripts, programming libraries, and managed file transfer systems. This avoids having to handle recurring file transfers manually. SFTP was designed to make automation much simpler than standard FTP.

Priya Mervana

Priya Mervana

Verified Badge Verified Web Security Experts

Priya Mervana is working at SSLInsights.com as a web security expert with over 10 years of experience writing about encryption, SSL certificates, and online privacy. She aims to make complex security topics easily understandable for everyday internet users.