I am using the SSHJ library (https://github.com/shikhar/sshj).
I can use sshClient.newSCPFileTransfer(); to get my SCPClient object, but then the call to scpClient.download() requires either a String as the path for the destination file or a LocalDestFile object. All I want is to open a stream to download the file to. Is there a way to easily do this using SSHJ?
I looked at the different implementations of LocalDestFile, but nothing seemed applicable to this use case.
The specific use case is downloading a remote file and streaming it to a client’s browser for a web app. I have to use SCP for this and thus want to use the SSHJ library.
I was able to solve this by extending the
InMemoryDestFileclass and passing my desiredOutputStreamobject into the constructor and having it returned in thegetOutputStreammethod.An example is shown in the following GIST: https://gist.github.com/2157565
It seems that you need to close the
OutputStreamon your own when you are done, so watch out for that.