|
|||||||||
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(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,
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. |
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 |
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(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 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)Method Detail |
---|
public boolean command(java.lang.String command)
SSHConsoleRemote
command
in interface SSHConsoleRemote
command
- command line to run
public boolean command(java.lang.String command, boolean pty)
command
- command line to runpty
- whether to allocate a pty 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.
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
. 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.
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. This method also redirects
stderr to the given OutputStream
.
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, java.io.OutputStream stdout, java.io.OutputStream stderr, boolean pty)
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. This method also redirects
stderr to the given OutputStream
.
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, 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
. 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. This method also redirects
stderr to the given OutputStream
.
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 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 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 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(long timeout) throws TimeoutException
timeout
- timeout time in milliseconds
TimeoutException
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
changeStdOut
in interface SSHConsoleRemote
out
- new stdout streampublic java.io.InputStream getStdOut()
SSHConsoleRemote
getStdOut
in interface SSHConsoleRemote
public java.io.OutputStream getStdIn()
SSHConsoleRemote
getStdIn
in interface SSHConsoleRemote
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |