I found a case where I need to implement something of this concept:
"gzip /tmp/sample.txt | ssh email@example.com gunzip -c > /tmp/sample.txt"
I'm implementing a client that gzip's the file and send it to a remote machine
in stdin. Here's a snip of my implementation:
// Create the GZIP output stream
ByteArrayOutputStream baosGZipped = new ByteArrayOutputStream ();
GZIPOutputStream gzOut = new GZIPOutputStream(baosGZipped);
// Open the input file
FileInputStream src = new FileInputStream(sourceFileName);
byte buf = new byte;
while ((len = src.read(buf)) > 0)
// Complete the GZIP file
ClientChannel channel = session.createExecChannel("gunzip -c >" + destFile);
ByteArrayInputStream in = new ByteArrayInputStream(baosGZipped.toByteArray());
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
What I discovered is that this will never end !!!
The problem is, that there's a pumpInputStream in ClientInputStreamPump thread (org/apache/sshd/client/channel/ChannelSession.java),
that will never end until closeFuture.isClosed. Since this does not happen, the unzip in the remote host doesn't end, and the channel will
never close. This prevents the client from a proper pipe implementation.
There should be a method to properly end this while-loop thus the remote side will be able to finish and close.
public void CloseStream()
and change pumpInputStream like this:
+while (!closeFuture.isClosed() && !streamStop)