com.mindbright.ssh2
public class SSH2ConsoleRemote extends java.lang.Object implements SSHConsoleRemote
SSH2SCP1Client
.
To create a SSH2ConsoleRemote
instance a complete
connected ssh2 stack is needed from which one provides the
SSH2Connection
to the constructor.
SSH2Connection
,
SSH2SimpleClient
Modifier and Type | Field and Description |
---|---|
protected SSH2Connection |
connection |
protected SSH2SessionChannel |
session |
protected java.io.OutputStream |
stderr |
protected java.io.OutputStream |
stdout |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected SSH2Connection connection
protected SSH2SessionChannel session
protected java.io.OutputStream stdout
protected java.io.OutputStream stderr
public SSH2ConsoleRemote(SSH2Connection connection)
connection
- connected connection layerpublic 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)public boolean command(java.lang.String command)
SSHConsoleRemote
Note, this will create an extra pair of threads to handle the data.
command
in interface SSHConsoleRemote
command
- command line to runpublic 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 notpublic 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 topublic 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 notpublic 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 notpublic 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 notpublic 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 terminalpublic 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 terminalpublic boolean shell()
SSHConsoleRemote
shell
in interface SSHConsoleRemote
public boolean shell(boolean pty)
pty
indicates whether to allocate a PTY or not.pty
- indicates whether to allocate a PTY or notpublic 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 terminalpublic 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 terminalpublic 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 runpublic 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 millisecondspublic int waitForExitStatus(long timeout) throws TimeoutException
timeout
- timeout time in millisecondsTimeoutException
public boolean sendBreak(int length)
length
- the BREAK length (ms)public void close()
SSHConsoleRemote
close
in interface SSHConsoleRemote
public void close(boolean waitforcloseconfirm)
SSHConsoleRemote
close
in interface SSHConsoleRemote
public void changeStdOut(java.io.OutputStream out)
SSHConsoleRemote
Note that this method only works if the underlying session uses blocking streams and threads.
changeStdOut
in interface SSHConsoleRemote
out
- new stdout streampublic java.io.InputStream getStdOut()
SSHConsoleRemote
Note that this method returns null if the underlying stream uses non-blocking io
getStdOut
in interface SSHConsoleRemote
public java.io.OutputStream getStdIn()
SSHConsoleRemote
Note 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
SSHConsoleRemote
Note that this method only works if the underlying session uses non-blocking io.
changeStdOut
in interface SSHConsoleRemote
out
- new stdout streamjava.lang.IllegalArgumentException
public NonBlockingOutput getNBStdIn()
SSHConsoleRemote
Note that this method returns null if the underlying stream uses blocking io
getNBStdIn
in interface SSHConsoleRemote
public NonBlockingInput getNBStdOut()
SSHConsoleRemote
Note that this method returns null if the underlying stream uses blocking io
getNBStdOut
in interface SSHConsoleRemote