What does the `-C` flag exactly do in `scp`?

It's never really going to make any big difference, but zipping the file before copying it ought to be a little bit less efficient since using a container format such as zip that can encapsulate multiple files (like tar) is unnecessary and it is not possible to stream zip input and output (so you need a temporary file).

Using gzip on the other hand, instead of zip ought to be exactly the same since it's what ssh -C does under the hood... except that gzipping yourself is more work than just using ssh -C.


The -C flag enables a gzip compression of an SSH stream.

It's an equivalent of Accept-Encoding: gzip in HTTP.

How the flag performs depends on a kind of data you transfer:

  • When transferring a single large file, the performance would be near the same to zipping the file before the transfer (neglecting efficiency of zip vs. gzip algorithm).

    But using -C is a less effort for you as an user.

  • When transferring a lots of small files, the performance will be inferior to zipping the files before transfer.

    A reason behind that is, that before each file transfer, there's an interactive communication between the SCP server and the client (for exchanging file metadata, like timestamp and permissions). So both sides have to wait a bit for the other side to respond (compression won't help while waiting). That's a wasted time for each transferred file. How much time is wasted depends on a latency of the connection. In the end, the transfer can be magnitudes slower.

    When you transfer a single zipped file, that communication happens only once.


It enables the gzip compression in ssh (under the scp).

On slow connections this will speed things up, on any reasonably fast connection ( 100Mbit or faster) the compression is very likely to slow things down.

It will be more or less efficient than zip based on whether gzip (specifically gzip -6) would be more or less efficient than your chosen zip compression level