hierynomus / sshj

ssh, scp and sftp for java
Apache License 2.0
2.5k stars 601 forks source link

Executing one command and then other #204

Closed icemagno closed 9 years ago

icemagno commented 9 years ago

Hi, I trying to do a command sequence:

    Session session = ssh.startSession();
    Session.Command cmd = session.exec("ls -l");
    System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
    cmd.join(10, TimeUnit.SECONDS);
    Session.Command cmd2 = session.exec("ls -a");
    System.out.println(IOUtils.readFully(cmd2.getInputStream()).toString());

And I can't because a library limitation:

This session channel is all used up

So I ask what this library is for if it can't remember what the user i doing? Is not so useful if I cannot even change folders, check content and do some action on files ....

hierynomus commented 9 years ago
  1. Please try to be friendly and constructive if you want help regarding your problem.
  2. Please have a look at the JavaDoc of Session, which specifies that a Session is used up as soon as you start using it for one thing.

If you want to execute a series of commands, I suggest you either concatenate them (using && or ;), or use the Shell which gives you an interactive process.

icemagno commented 9 years ago

Thanks for reply. I can't do such thing because I'm in a web environment and I don't know what the user are doing, so I can't pipe commands ( the user can if he wants, but I will never know). I must keep a connected session to allow the user access the terminal any time he wants. I solved this by using ExpectIT with SSHJ

`

net.sf.expectit expectit-core 0.7.0

`

Now I have a perfect WEB interface for a SSH and can issue very interactive commands like SUDO (with passwords) and reply SO questions like (Yes/No) , (Enter your name) , etc.... http://eic-cefet-rj.github.io/sagitarii/img/ssh-03.png

By the way, I may need your logo or something else to put in system's "Tech Badges" list. http://eic-cefet-rj.github.io/sagitarii/img/login.png So everybody will know the great technologies is making my system possible.

Thanks for your help. (and my apologies if I was rude)

hierynomus commented 9 years ago

Wow, looks cool! Glad you found a way to make it work. Apologies accepted ;). You could also have a look at a higher level abstraction we built, that allows more protocols (https://github.com/xebialabs/overthere)