Java and SSH: maintaining a connection -
Target: Remote control SS server with a connection and multiple sessions or a continuous session. Problem 1: I am currently using sshj to do some remote control through SSH and it works well, but I think it is the right way to handle it. Indicates (the host does not provide the true root, just the pseudo-i will have to log in before). Problem 2: I'm downloading XPtags to handle quickly but I can not understand for my life how to maintain the session after logging in once and being certified as root.
The current hack solution requires that I log in again every time:
than the public class {spawn shell; ExpectJ exp; String host; Int port; String user name; String password; Boolean pseudo = false; Public expectations (string host, int port, string username, string passwd) throws IOException, timeout exposure, expedgexation {exp = new ExpectJ (5); This.host = host; This.port = port; This.username = Username; This.passwd = passwd; Shell = exp.spawn (host, port, username, passwd); Shell.send ("sudo netstat -natvp | grep Xtightvnc \ n"); Println (shell.getCurrentStandardOutContents ()); {Shell.expect (Try "[sudo] password for" ####### "); Shell.send (password + "\ n"); } Hold (IOException pre) {string error = ex.toString (); If (Err.equals ("java.io.ioException: reached end of stream, no mail found")) () New IOException (ex); }}}
Question 1: What can be done "sshj" rather than prompting the password? I can not write anything about that kind of control.
Quetion 2: How can I modify the above mentioned code to keep a constant connection from which I can make many calls? I have reached the status of authentication once as a root, but the spawn always stops after the initial command is sent, I want to continue to talk again. Question 1: Can sshj be used to "expect" a password prompt? I have a control for that type of control The document could not be found.
The main which sshj provides is a handle on the I / O stream of shell or command, and there are ways to get stuff like the exit position. / P>
Quetion 2: I expect the above to maintain a constant connection How can I modify the code from which I can make many calls? I have reached the status of authentication as the root but the spawn always stops when the initial command is sent, I want to continue to talk again
Multiplexing session, even a concurrent session, supports a single SSH connection, but note that there can be only one session for a shell / command / subsystem.
What type of session are you using, like the session shell (via session.start.Shell) or session.) In the latter case, once you execute a command, So the session stands for and it is expected behavior.
Normally the shell will not recommend the command because you are equipped with Exclaims, which I think that prompts and in this way, if you want to go to that path if you want to resonate the letters or If there are such problems, then play with the PTY option (rather than session. Alant default PTY call session.allocatePTY which takes a full bunch of parts, take a look at it).
Code example:,
In addition, if you shrink the issue down with a sshj in a bug, then report it to the problem tracker :)
< / Div>
Comments
Post a Comment