|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mindbright.ssh2.SSH2ConsoleRemote
public class SSH2ConsoleRemote
This class implements a console to a remote command or shell. The underlying
mechanism is a session channel which is created on demand from the provided
connection layer. It can be used to execute single commands and/or control
input/output to/from a shell. It is for example extended to control an SCP1
client in the class SSH2SCP1Client.
To create a SSH2ConsoleRemote instance a complete
connected ssh2 stack is needed from which one provides the
SSH2Connection to the constructor.
SSH2Connection,
SSH2SimpleClient| Field Summary | |
|---|---|
protected SSH2Connection |
connection
|
protected SSH2SessionChannel |
session
|
protected java.io.OutputStream |
stderr
|
protected java.io.OutputStream |
stdout
|
| Constructor Summary | |
|---|---|
SSH2ConsoleRemote(SSH2Connection connection)
Basic constructor. |
|
SSH2ConsoleRemote(SSH2Connection connection,
java.io.OutputStream stdout,
java.io.OutputStream stderr)
Constructor to be used to preset the stdout and/or stderr output streams to which the correspondings streams should be redirected to. |
|
| Method Summary | |
|---|---|
void |
changeStdOut(NonBlockingOutput out)
Changes the output stream where stdout is written to in the underlying session channel. |
void |
changeStdOut(java.io.OutputStream out)
Changes the output stream where stdout is written to in the underlying session channel. |
void |
close()
Closes the session channel. |
void |
close(boolean waitforcloseconfirm)
Closes the session channel. |
boolean |
command(java.lang.String command)
Runs single command on server. |
boolean |
command(java.lang.String command,
boolean pty)
Runs single command on server. |
boolean |
command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr)
Runs single command on server and redirects stdout to the given NonBlockingOutput. |
boolean |
command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty)
Runs single command on server and redirects stdout to the given NonBlockingOutput. |
boolean |
command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
Runs single command on server and redirects stdout to the given NonBlockingOutput. |
boolean |
command(java.lang.String command,
java.io.OutputStream stdout)
Runs single command on server and redirects stdout to the given OutputStream. |
boolean |
command(java.lang.String command,
java.io.OutputStream stdout,
boolean pty)
Runs single command on server and redirects stdout to the given OutputStream. |
boolean |
command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr)
Runs single command on server and redirects stdout to the given OutputStream. |
boolean |
command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr,
boolean pty)
Runs single command on server and redirects stdout to the given OutputStream. |
boolean |
command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
Runs single command on server and redirects stdout to the given OutputStream. |
boolean |
commandWithTerminal(SSH2TerminalAdapter termAdapter,
java.lang.String command)
Run a command on the server and connect it to the given terminal. |
NonBlockingOutput |
getNBStdIn()
Gets the stdin stream of the underlying session channel. |
NonBlockingInput |
getNBStdOut()
Gets the stdout stream of the underlying session channel. |
java.io.OutputStream |
getStdIn()
Gets the stdin stream of the underlying session channel. |
java.io.InputStream |
getStdOut()
Gets the stdout stream of the underlying session channel. |
boolean |
sendBreak(int length)
Send a BREAK to the remote session (see draft-ietf-secsh-break for more information) |
boolean |
shell()
Starts an interactive shell on the server, note that no PTY is allocated. |
boolean |
shell(boolean pty)
Starts an interactive shell on the server. |
boolean |
shell(boolean pty,
java.lang.String termType,
int rows,
int cols)
Starts an interactive shell on the server. |
boolean |
shell(NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr)
Starts an interactive shell on the server. |
boolean |
shell(NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
Starts an interactive shell on the server. |
boolean |
terminal(SSH2TerminalAdapter termAdapter)
Start an interactive shell on the server and connect it to the given terminal. |
int |
waitForExitStatus()
Retrieves the exit status reported by the command/shell run. |
int |
waitForExitStatus(int timeout)
Retrieves the exit status reported by the command/shell run. |
int |
waitForExitStatus(long timeout)
Waits for the command to finish within the given time. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected SSH2Connection connection
protected SSH2SessionChannel session
protected java.io.OutputStream stdout
protected java.io.OutputStream stderr
| Constructor Detail |
|---|
public SSH2ConsoleRemote(SSH2Connection connection)
connection - connected connection layer
public SSH2ConsoleRemote(SSH2Connection connection,
java.io.OutputStream stdout,
java.io.OutputStream stderr)
command() method.
connection - connected connection layerstdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)| Method Detail |
|---|
public boolean command(java.lang.String command)
SSHConsoleRemoteNote, this will create an extra pair of threads to handle the data.
command in interface SSHConsoleRemotecommand - command line to run
public boolean command(java.lang.String command,
boolean pty)
Note, this will create an extra pair of threads to handle the data.
command - command line to runpty - whether to allocate a pty on the server or not
public boolean command(java.lang.String command,
java.io.OutputStream stdout)
OutputStream.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdout - the output stream to redirect stdout to
public boolean command(java.lang.String command,
java.io.OutputStream stdout,
boolean pty)
OutputStream. It is also possible to allocate a
pty for the command on the server.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdout - the output stream to redirect stdout topty - whether to allocate a pty or not
public boolean command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr)
OutputStream. This method also redirects stderr to
the given OutputStream.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)
public boolean command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr)
NonBlockingOutput. This method also redirects stderr to
the given NonBlockingOutput.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdin - the input stream to read input from (can be null)stdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)
public boolean command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr,
boolean pty)
OutputStream. This method also redirects stderr to
the given OutputStream. It is also possible to
allocate a pty for the command on the server.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)pty - whether to allocate a pty or not
public boolean command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty)
NonBlockingOutput. This method also redirects stderr to
the given NonBlockingOutput. It is also possible
to allocated a pty for the remote command.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdin - the input stream to read input from (can be null)stdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)pty - whether to allocate a pty or not
public boolean command(java.lang.String command,
java.io.OutputStream stdout,
java.io.OutputStream stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
OutputStream. This method also redirects stderr to
the given OutputStream. This method can also set
the terminal type and layout for the remote command. It is also
possible to allocated a pty for the remote command.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)pty - whether to allocate a pty or nottermType - indicates which terminal type to requestrows - indicates the number of rows on the terminalcols - indicates the number of columns on the terminal
public boolean command(java.lang.String command,
NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
NonBlockingOutput. This method also redirects stderr to
the given NonBlockingOutput. This method can also set
the terminal type and layout for the remote command. It is also
possible to allocated a pty for the remote command.
Note that the call will return once the command has been launched on the server and that it does not wait until the command has completed. For waiting look at the waitForExitStatus() method.
Note, this will create an extra pair of threads to handle the data.
command - command line to runstdin - the input stream to read input from (can be null)stdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)pty - whether to allocate a pty or nottermType - indicates which terminal type to requestrows - indicates the number of rows on the terminalcols - indicates the number of columns on the terminal
public boolean shell()
SSHConsoleRemote
shell in interface SSHConsoleRemotepublic boolean shell(boolean pty)
pty indicates whether to allocate a PTY or not.
pty - indicates whether to allocate a PTY or not
public boolean shell(boolean pty,
java.lang.String termType,
int rows,
int cols)
pty indicates whether to allocate a PTY or not.
pty - indicates whether to allocate a PTY or nottermType - indicates which terminal type to requestrows - indicates the number of rows on the terminalcols - indicates the number of columns on the terminal
public boolean shell(NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr)
pty indicates whether to allocate a PTY or not.
This method redirects stdin, stdout and stderr to the provided
non blocking streams. It is also possible to setup the terminal
type to run in.
stdin - the input stream to read input from (can be null)stdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)
public boolean shell(NonBlockingInput stdin,
NonBlockingOutput stdout,
NonBlockingOutput stderr,
boolean pty,
java.lang.String termType,
int rows,
int cols)
pty indicates whether to allocate a PTY or not.
This method redirects stdin, stdout and stderr to the provided
non blocking streams. It is also possible to setup the terminal
type to run in.
stdin - the input stream to read input from (can be null)stdout - the output stream to redirect stdout to (can be null)stderr - the output stream to redirect stderr to (can be null)pty - indicates whether to allocate a PTY or nottermType - indicates which terminal type to requestrows - indicates the number of rows on the terminalcols - indicates the number of columns on the terminal
public boolean terminal(SSH2TerminalAdapter termAdapter)
termAdapter - identifies the terminal window to associate
the shell with.
public boolean commandWithTerminal(SSH2TerminalAdapter termAdapter,
java.lang.String command)
termAdapter - identifies the terminal window to associate
the shell with.command - command line to run
public int waitForExitStatus()
close()) in which case
the status returned will be -1.
public int waitForExitStatus(int timeout)
close()) in which case
the status returned will be -1.
timeout - timeout in milliseconds
public int waitForExitStatus(long timeout)
throws TimeoutException
timeout - timeout time in milliseconds
TimeoutExceptionpublic boolean sendBreak(int length)
length - the BREAK length (ms)
public void close()
SSHConsoleRemote
close in interface SSHConsoleRemotepublic void close(boolean waitforcloseconfirm)
SSHConsoleRemote
close in interface SSHConsoleRemotepublic void changeStdOut(java.io.OutputStream out)
SSHConsoleRemoteNote that this method only works if the underlying session uses blocking streams and threads.
changeStdOut in interface SSHConsoleRemoteout - new stdout streampublic java.io.InputStream getStdOut()
SSHConsoleRemoteNote that this method returns null if the underlying stream uses non-blocking io
getStdOut in interface SSHConsoleRemotepublic java.io.OutputStream getStdIn()
SSHConsoleRemoteNote that this method returns null if the underlying stream uses non-blocking io
getStdIn in interface SSHConsoleRemote
public void changeStdOut(NonBlockingOutput out)
throws java.lang.IllegalArgumentException
SSHConsoleRemoteNote that this method only works if the underlying session uses non-blocking io.
changeStdOut in interface SSHConsoleRemoteout - new stdout stream
java.lang.IllegalArgumentExceptionpublic NonBlockingOutput getNBStdIn()
SSHConsoleRemoteNote that this method returns null if the underlying stream uses blocking io
getNBStdIn in interface SSHConsoleRemotepublic NonBlockingInput getNBStdOut()
SSHConsoleRemoteNote that this method returns null if the underlying stream uses blocking io
getNBStdOut in interface SSHConsoleRemote
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||