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 aGetmethod that saves it to a local file — close -
class
SshStream, which might do kind of what I want, but seems disjoint fromSftpso 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?
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
ChannelSftpmethods that call forOutputStreams 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
Streamclass 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;