fengjian1993 commented on issue #103: [1.1.x]question about use mina-sshd as 
ssh-client and send shell command
URL: https://github.com/apache/mina-sshd/pull/103#issuecomment-499405129
 
 
   > 
   > 
   > Here is sketch of how I would do it (assuming the latest version) - for 
more details see `SshClientMain` class in the project.
   > 
   > ```java
   > SshClient client = SshClient.setUpDefaultClient();
   > client.start();
   > while (...keep running...) {
   >     try (ClientSession session = 
client.connect(.....).verify(...timeout...).getSession()) {
   >         session.addPasswordIdentity(....);   // or addKeyIdentity...
   >         session.auth().verify(...timeout...);
   > 
   >         try (ClientChannel channel = session.createShellChannel(....)) {
   >              channel.setIn(new NoCloseInputStream(System.in));
   >              channel.setOut(new NoCloseOutputStream(System.out));
   >              channel.setErr(new NoCloseOutputStream(System.err));
   >              channel.open().verify(....timeout...);
   >              // This causes this thread to block until shell is closed...
   >              channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L);
   >         }
   >     }
   > }
   > client.stop();
   > ```
   
   Yeah, i have tried that.
   But that is a interaction via console. I wanna send command by java code, 
such as inputstream and read message which returned by ssh server by output 
stream. Of course, i want keep channel(or session) until i close it so that i 
can send command and receive message constantly. :) Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to