How to use data compression for FTP/FTPS

Some FTP/FTPS servers support what is called MODE Z data compression to reduce the amount of data that is transmitted. Both the client and server 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.

An example of how to enable MODE Z compression is shown below. An FTPException will be thrown if MODE Z is not supported.

ftp.enableModeZCompression();