using Rebex.Net;

Welcome to using Rebex.Net; Sign in | Help
in Search

Using Rebex.Net

News and announcements about Rebex.NET components

HOWTO: Transfer compression in SFTP and SSH Shell

A feature that is requested very often is integrated transfer compression in Rebex SFTP. This is particularly useful when transferring text files or other highly compressible files, and a similar feature is already included in Rebex FTP. So why does it take so long to add this to SFTP as well? The problem is that the .NET Framework compression API is well-suited to be used in protocols utilizing stream transfer modes such as FTP, but entirely unsuitable for protocols using block transfer mode such as SSH, the underlying protocol used by SFTP.

Fortunately, since build 3428, it is possible to enable ZLIB compression in Rebex SFTP and Rebex SSH Shell using ZlibStream for .NET, a library build on top of a C# port of JCraft's Java JZlib library. JZlib is a re-implementation of zlib in pure Java. It is covered by a BSD-style license, which makes it possible to be used for free (even in commercial closed-source applications).

OK, so how to enable transfer compression? It is rather simple – download and install ZlibStream for .NET, add a reference to Rebex.ZlibStream.dll to your application and when connecting to an SFTP server in your code, add few additional lines:

C#

Sftp sftp = new Sftp();
SshParameters parameters = new SshParameters();
parameters.CompressionStreamType = typeof(Rebex.IO.Compression.JZlib.ZlibOutputStream);
sftp.Connect(hostname, password, parameters);

VB.NET

Dim sftp As New Sftp
Dim parameters As New SshParameters
parameters.CompressionStreamType = GetType(Rebex.IO.Compression.JZlib.ZlibOutputStream)
sftp.Connect(hostname, password, parameters)

In Rebex SSH Shell, an equivalent code can be used.

At this point, you may be asking yourself – why is this not included in Rebex components by default? There are two reasons:

  1. A BSD-style license requires that all derivative works reproduce the full text of the license in the source code and documentation. This goes against our philosophy for .NET components - we don’t want our clients to still bother with licensing issues after they purchased a license.
  2. Some of our clients have a strict no-free-software policy that forbids them from using anything based on or derived from a software using an open source license. Therefore, no free or open source code is allowed into the codebase of products we sell.

To address this, we are currently implementing a new ZLIB compression library from scratch, without using any third-party code. Once this is finished, Rebex SFTP and SSH Shell will finally support transfer compression by default. Until then, simply use ZlibStream for .NET as described above.

Published Tuesday, June 09, 2009 3:58 PM by Lukas Pokorny
Filed under: ,

Comments

No Comments
New Comments to this post are disabled
Powered by Community Server (Personal Edition), by Telligent Systems