The `Sftp` class does not require you to specify the position and length in the `GetDownloadStream` method. Instead, you can normally use the `Seek` of the stream object returned by the `GetDownloadStream` or `GetUploadStream` method.
Here is an example of using that method:
using System.IO;
using ComponentPro.Compression;
using ComponentPro.Net;
...
// Create a new class instance.
using (Sftp client = new Sftp())
{
// Connect to the SFTP server.
client.Connect("192.168.0.211");
// Authenticate.
client.Authenticate("test", "test");
// ...
// Get download stream for remote file 'uncompressed.dat'.
Stream istream = client.GetDownloadStream("/compressed.z", SeekOrigin.Begin, 1024);
// Create new file
FileStream fo = new FileStream("d:\\temp\\uncompressed2.dat", FileMode.Create);
// Create a new instance of the ZlibInputStream for the compression.
ZlibStream zs = new ZlibStream(istream);
byte[] buf = new byte[8192];
int read;
while ((read = zs.Read(buf, 0, 8192)) > 0) // Read from the download stream.
{
fo.Write(buf, 0, read); // And write to the compression Zlib stream.
}
zs.Close();
fo.Close();
// ...
}
answered 12/12/2017 9:47:14 AM