Question

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.

Was it helpful?

Solution

I was able to solve this by extending the InMemoryDestFile class and passing my desired OutputStream object into the constructor and having it returned in the getOutputStream method.

An example is shown in the following GIST: https://gist.github.com/2157565

It seems that you need to close the OutputStream on your own when you are done, so watch out for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top