Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Downloading and returning a non blocking stream of data using SSH.Net

$
0
0
I am using the ssh.net library for performing SFTP operations to work with large data files (>=500MB)

I am having an issue with how to return the data in a non-blocking way.

The ftpClient.DownloadFile() method signature is ok, when writing to a file or if there's some way I can instantiate the stream, but am having problems on how to use it when I want to return a stream without blocking.

All the examples I have seen so far will be writing the download to a Filestream. Nothing that just returns a stream

With .Net's built-in FTP, you just use response.GetResponseStream(), and it streams back the data, without blocking.

The only way round to using it in a return statement was writing to a temporary file. But this results in it being a blocking operation.

var tmpFilename = "temp.dat";
        int bufferSize = 4096;
        var sourceFile = "23-04-2015.dat";

        using (var stream = System.IO.File.Create(tmpFilename , bufferSize, System.IO.FileOptions.DeleteOnClose))
        {
            sftpClient.DownloadFile(sourceFile, stream);
            return stream;
        }
I don't want it to block but to stream back the data.

I also would like to avoid creating a temporary file.

Is there an alternative implementation to make it stream back the data?

Or is there an alternative stream I can instantiate(except for MemoryStream), that would work with large files?

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>