Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6.8k views
in .NET FTP by (220 points)
Hi
Maybe someone can provide some guidience. I belive the EnterpriseDT.Net.Zlib will give me the ability to compress before i transfer .If so can some one provide a example of this functionality in vb.net 2005

Thanks
Bob

3 Answers

0 votes
by (51.4k points)
EnterpriseDT.Net.Zlib is really intended for internal use only. I suggest you use System.IO.Compression.GZipStream instead. Here's an example which uploads a compressed version of the byte-array, uploadData, to the server; downloads it again; decompresses it and puts it into downloadData:
// Set up FTPConnection
FTPConnection connection = new FTPConnection();
connection.ServerAddress = serverAddress;
connection.UserName = userName;
connection.Password = password;

// Connect to server
connection.Connect();

// Compress data into uploadBuffer
MemoryStream uploadBuffer = new MemoryStream();
GZipStream compressor = new GZipStream(uploadBuffer, CompressionMode.Compress, true);
compressor.Write(uploadData, 0, uploadData.Length);
compressor.Dispose();

// upload the uploadBuffer
connection.UploadStream(uploadBuffer, fileName);

// download into downloadBuffer
MemoryStream downloadBuffer = new MemoryStream();
connection.CloseStreamsAfterTransfer = false;
connection.DownloadStream(downloadBuffer, fileName);

// decompress it
downloadBuffer.Seek(0, SeekOrigin.Begin);
GZipStream decompressor = new GZipStream(downloadBuffer, CompressionMode.Decompress);
MemoryStream data = new MemoryStream();
byte[] buffer = new byte[1024];
int numBytes;
while ((numBytes=decompressor.Read(buffer, 0, buffer.Length))>0)
    data.Write(buffer, 0, numBytes);

// copy the byte-array into downloadData
downloadData = data.ToArray();

// close the connection
connection.Close();


A few things to note:
  • You must call Dispose on the GZipStream when you've finished writing your data to it.
  • You must set CloseStreamsAfterTransfer to false before downloading into the stream.
  • You must seek back to the beginning of the downloaded stream before reading the data.


- Hans (EnterpriseDT)
0 votes
by (220 points)
Thank you very much for the quicke response
This will get me going

Thanks
Bob g
0 votes
by (161k points)
Note that edtFTPnet/PRO and edtFTPnet/Express now support MODE Z compression (which uses zlib).

Categories

...