Open menu

Learn

SFTP Binary Mode

In this article, we will focus on both SFTP binary and ASCII modes, shedding light on what they are, their importance, and their usage.

File Transfer Modes: ASCII vs Binary

Before delving into the binary mode in SFTP, it's essential to understand the two primary file transfer modes: ASCII and binary. ASCII mode is designed for text files, such as HTML or plain text documents. When transferring files in ASCII mode, the protocol automatically converts line endings to match the target system's standard format—CR/LF (Carriage Return/Line Feed) for Windows systems and LF (Line Feed) for Unix systems. On the other hand, binary mode is used for transferring non-text files—images, executables, zip files, and so forth. Unlike ASCII mode, binary mode transfers files exactly as they are, without any conversion of line endings or any other characters. This makes binary mode more universally applicable, as it can also be used to transfer text files without changing their content.

Understanding SFTP Binary mode

In SFTP, binary mode is the default and often the only mode used for file transfer. This is because SFTP, unlike FTP, does not distinguish between ASCII and binary modes. SFTP transfers all files in binary mode, whether they're text or non-text files. As a result, when using SFTP, you don't need to worry about switching between ASCII and binary modes depending on the type of file you're transferring. Starting with SFTP version 4 and onwards, support for ASCII mode was introduced. This allows the protocol to handle text and non-text files differently, much like the older FTP protocol. When using these newer versions of SFTP, you have the option to switch between ASCII and binary modes, depending on the type of file you're transferring. However, most SFTP servers (including OpenSSH, the most popular one) support only SFTP v3 and have no plans to support v4, v5, or v6.