开发者

How to get a Stream object for a remote file on SFTP using SharpSSH library?

How can I get a Stream object to read the file that is on SFTP share? I see that there is functionality to download 开发者_C百科a file from SFTP using Sftp class, but I need a Stream object to be able to show the download progress.


I'm not familiar with SharpSSH, but edtFTPnet/PRO, which is a commercial .NET library supporting SFTP and FTPS, uses a BytesTransferred event that you can subscribe to.

So you regularly get notified of how much has been downloaded or uploaded, and if you grab the size before transferring, you can easily then calculate download progress.

I assume SharpSSH has a similar event you can subscribe to.


Try to download SSH.NET Library from CodePlex

This library has a method to download a file

public void DownloadFile(string path, Stream output);

But I use the method System.Net.WebClient.DownloadData to get a file in sftp server, this method returns a byteArray, you can easyly convert to Stream.

WebClient client = new WebClient();
byte[] file = client.DownloadData(url);
Stream stream = new MemoryStream(file); 

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜