从 SharpSSH 流式传输文件
我正在尝试使用 SharpSSH 从远程 SFTP 服务器获取文件,并且我想将其作为流读出。
我发现:
class
Sftp
,它有一个Get
方法,可以将其保存到本地文件--closeclass
SshStream
,它可能会做我想要的事情,但似乎与Sftp
所以我可能必须自己实现 SFTP 部分 (??)class
ChannelSftp
,它实现了get(String, OutputStream)
等 SFTP 方法 code>,这看起来很完美,除了它是一个低级类,而且对我来说如何实例化它一点也不明显
它看起来就像 Sftp
的 ChannelSftp SftpChannel
属性不是私有的,我可以使用它,一切都会很完美。不过,如果可能的话,我想避免破解 SharpSSH。
我错过了什么吗?
I'm trying to use SharpSSH to get a file from a remote SFTP server, and I want to read it out as a stream.
I found:
class
Sftp
, which has aGet
method that saves it to a local file -- closeclass
SshStream
, which might do kind of what I want, but seems disjoint fromSftp
so I might have to implement the SFTP part myself (??)class
ChannelSftp
, which implements SFTP methods likeget(String, OutputStream)
, which seems perfect, except it's a low-level class and it's not at all obvious to me how to even instantiate it
It looks like if Sftp
's ChannelSftp SftpChannel
property wasn't private, I could use that and everything would be perfect. I'd like to avoid hacking up SharpSSH if possible, though.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了一些问题,并进行了测试。尝试一下,然后随意使用 API。
首先,您需要显示一个方法,该方法允许您利用调用
OutputStream
而不是目标文件名的ChannelSftp
方法。如果您不想使用反射来完成此操作,请将此方法添加到Sftp类中并重新编译SharpSSH。接下来,为与 Tamir.SharpSsh.java.io.OutputStream 兼容的 Stream 类创建一个包装器,如下所示:
有了这些成分,您现在可以使用 OpenSSH 将其数据传输到您选择的流,如下面使用
FileStream
所示。使用系统.IO;
使用 Tamir.SharpSsh;
I worked something out, and tested it out. Give it a try, and feel free to massage the API.
First off, you will need to surface up a method that allows you to take advantage of the
ChannelSftp
methods that call forOutputStream
s instead of destination file names. If you don't want to use reflection to do it, then add this method to the Sftp class and recompile SharpSSH.Next, create a wrapper for the
Stream
class that is compatible withTamir.SharpSsh.java.io.OutputStream
, such as the one below:With those ingredients, you can now use OpenSSH to stream its data to the stream of your choice, as demonstrated below with a
FileStream
.using System.IO;
using Tamir.SharpSsh;