It depends on the protocol you are using to transfer files. Usually it is already done transparently.
HTTP (and HTTPS) protocol supports on-the-fly compression, provided that both server and client implements it. First of all, client will let server knows which type of compression it supports. Typical HTTP request header includes a line like
Accept-Encoding: gzip, deflate
Server will pick a compression algorithm it supports, indicate in the HTTP header (as below) and serve the contents compressed.
Content-Encoding: gzip
Most modern HTTP clients (like Chrome, Firefox, Internet Explorer, Safari etc, in alphabetical order) and servers (like Apache, Microsoft IIS, nginx) when configured properly, are transferring data compressed on-the-fly.
Similarly other protocols may implement compression, e.g. Mode Z in FTP. Specialized protocols such as Remote Differential Compression by Microsoft allows synchronizing local and remote files by transferring the different portion only.
EDIT:
I found that the transparent HTTP compression is for file download only but not the other way round. If you wish to compress data for upload, you may need to write some Javascript, and make use of FileReader
and compression library like compressjs
.