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

发布于 2024-08-24 19:41:02 字数 92 浏览 3 评论 0原文

如何获取 Stream 对象来读取 SFTP 共享上的文件? 我看到有使用 Sftp 类从 SFTP 下载文件的功能,但我需要一个 Stream 对象才能显示下载进度。

How can I get a Stream object to read the file that is on SFTP share?
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯离梦残月幽梦 2024-08-31 19:41:02

我不熟悉 SharpSSH,但是 edtFTPnet/PRO,这是一个支持 SFTP 和 FTPS 的商业 .NET 库使用您可以订阅的 BytesTransferred 事件。

因此,您会定期收到有关已下载或上传的数量的通知,如果您在传输之前获取大小,则可以轻松计算下载进度。

我认为 SharpSSH 有类似的活动,您可以订阅。

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.

硬不硬你别怂 2024-08-31 19:41:02

尝试从 CodePlex 下载 SSH.NET 库

该库有一个下载文件的方法

public void DownloadFile(string path, Stream output);

,但我使用系统方法.Net.WebClient.DownloadData 获取sftp服务器中的文件,该方法返回一个byteArray,可以轻松转换为Stream。

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

希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文