简体   繁体   English

如何使用SharpSSH库在SFTP上获取远程文件的Stream对象?

[英]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? 如何获取Stream对象以读取SFTP共享上的文件? I see that there is functionality to download a file from SFTP using Sftp class, but I need a Stream object to be able to show the download progress. 我看到可以使用Sftp类从SFTP下载文件,但是我需要一个Stream对象才能显示下载进度。

Try to download SSH.NET Library from CodePlex 尝试从CodePlex下载SSH.NET库

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. 但是我使用System.Net.WebClient.DownloadData方法在sftp服务器中获取文件,此方法返回一个byteArray,可以轻松转换为Stream。

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

Hope this helps. 希望这可以帮助。

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. 我对SharpSSH不熟悉,但是edtFTPnet / PRO是一个支持SFTP和FTPS的商业.NET库,它使用BytesTransferred事件可以订阅。

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. 我认为SharpSSH有类似的活动可以订阅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM