@ Override public synchronized Reader executeCommandReader ( String command ) throws SshException , IOException { if ( ! isConnected ( ) ) { throw new IllegalStateException ( "Not connected!" ) ; } try { Channel channel = connectSession . openChannel ( "exec" ) ; ( ( ChannelExec ) channel ) . setCommand ( command ) ; InputStreamReader reader = new InputStreamReader ( channel . getInputStream ( ) , "utf-8" ) ; channel . connect ( ) ; return reader ; } catch ( JSchException ex ) { throw new SshException ( ex ) ; } }
Execute an ssh command on the server without closing the session so that a Reader can be returned with streaming data from the server .