How to use SFTP (data compression)

SFTP supports the use of data compression to reduce the amount of data that is transmitted. Both the client and server agree on a compression algorithm. They then compress data before sending and decompress data when it is received.

Compression and decompression both use CPU time, but if transmission speeds are slow, transfers can be sped up significantly, particularly if text files are being transferred. A compression factor of 10x is not unusual for text files. Media files are usually compressed already (e.g. JPEG and MPEG) and there will be little or no benefit in using compression. In fact with the added CPU time it may even be detrimental.

Typically, zlib compression is the compression algorithm most commonly supported in SFTP servers, and zlib is supported in edtFTPj/PRO. No compression is set as the default, and zlib is specified as an option. If the server forces use of zlib compression it will happen automatically.

If zlib compression is required (and is supported by the server), it should be set as the only compression option. This will force its use. To do this, all compression algorithms are disabled, then zlib is enabled, as shown below:

ftp.disableAllAlgorithms(SSHFTPAlgorithm.COMPRESSION);
ftp.setAlgorithmEnabled(SSHFTPAlgorithm.COMPRESSION_ZLIB, true);