|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.ethz.ssh2.Session
public class Session
A Session is a remote execution of a program. "Program" means
in this context either a shell, an application or a system command. The
program may or may not have a tty. Only one single program can be started on
a session. However, multiple sessions can be active simultaneously.
| Constructor Summary | |
|---|---|
protected |
Session(ChannelManager cm,
SecureRandom rnd)
|
| Method Summary | |
|---|---|
void |
close()
Close this session. |
void |
execCommand(String cmd)
Execute a command on the remote machine. |
void |
execCommand(String cmd,
String charsetName)
Execute a command on the remote machine. |
String |
getExitSignal()
Get the name of the signal by which the process on the remote side was stopped - if available and applicable. |
Integer |
getExitStatus()
Get the exit code/status from the remote command - if available. |
int |
getState()
|
InputStream |
getStderr()
|
OutputStream |
getStdin()
|
InputStream |
getStdout()
|
void |
requestDumbPTY()
Basically just a wrapper for lazy people - identical to calling requestPTY("dumb", 0, 0, 0, 0, null). |
void |
requestPTY(String term)
Basically just another wrapper for lazy people - identical to calling requestPTY(term, 0, 0, 0, 0, null). |
void |
requestPTY(String term,
int term_width_characters,
int term_height_characters,
int term_width_pixels,
int term_height_pixels,
byte[] terminal_modes)
Allocate a pseudo-terminal for this session. |
void |
requestX11Forwarding(String hostname,
int port,
byte[] cookie,
boolean singleConnection)
Request X11 forwarding for the current session. |
void |
startShell()
Start a shell on the remote machine. |
void |
startSubSystem(String name)
Start a subsystem on the remote machine. |
int |
waitForCondition(int condition_set,
long timeout)
This method blocks until certain conditions hold true on the underlying SSH-2 channel. |
int |
waitUntilDataAvailable(long timeout)
Deprecated. This method has been replaced with a much more powerful wait-for-condition interface and therefore acts only as a wrapper. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected Session(ChannelManager cm,
SecureRandom rnd)
throws IOException
IOException| Method Detail |
|---|
public void requestDumbPTY()
throws IOException
requestPTY("dumb", 0, 0, 0, 0, null).
IOException
public void requestPTY(String term)
throws IOException
requestPTY(term, 0, 0, 0, 0, null).
IOException
public void requestPTY(String term,
int term_width_characters,
int term_height_characters,
int term_width_pixels,
int term_height_pixels,
byte[] terminal_modes)
throws IOException
terminal_modes) is described in RFC4254.
term - The TERM environment variable value (e.g., vt100)term_width_characters - terminal width, characters (e.g., 80)term_height_characters - terminal height, rows (e.g., 24)term_width_pixels - terminal width, pixels (e.g., 640)term_height_pixels - terminal height, pixels (e.g., 480)terminal_modes - encoded terminal modes (may be null)
IOException
public void requestX11Forwarding(String hostname,
int port,
byte[] cookie,
boolean singleConnection)
throws IOException
hostname - the hostname of the real (target) X11 server (e.g., 127.0.0.1)port - the port of the real (target) X11 server (e.g., 6010)cookie - if non-null, then present this cookie to the real X11 serversingleConnection - if true, then the server is instructed to only forward one single
connection, no more connections shall be forwarded after first, or after the session
channel has been closed
IOException
public void execCommand(String cmd)
throws IOException
cmd - The command to execute on the remote host.
IOException
public void execCommand(String cmd,
String charsetName)
throws IOException
cmd - The command to execute on the remote host.charsetName - The charset used to convert between Java Unicode Strings and byte encodings
IOException
public void startShell()
throws IOException
IOException
public void startSubSystem(String name)
throws IOException
name - the name of the subsystem.
IOExceptionpublic int getState()
public InputStream getStdout()
public InputStream getStderr()
public OutputStream getStdin()
public int waitUntilDataAvailable(long timeout)
throws IOException
Session. Very useful
if you do not want to use two parallel threads for reading from the two
InputStreams. One can also specify a timeout. NOTE: do NOT call this
method if you use concurrent threads that operate on either of the two
InputStreams of this Session (otherwise this method may
block, even though more data is available).
timeout - The (non-negative) timeout in ms. 0 means no
timeout, the call may block forever.
0 if no more data will arrive.1 if more data is available.-1 if a timeout occurred.IOException
public int waitForCondition(int condition_set,
long timeout)
ChannelCondition) holds trueChannelCondition).
Note: do NOT call this method if you want to wait for STDOUT_DATA or STDERR_DATA and
there are concurrent threads (e.g., StreamGobblers) that operate on either of the two
InputStreams of this Session (otherwise this method may
block, even though more data is available in the StreamGobblers).
condition_set - a bitmask based on ChannelCondition valuestimeout - non-negative timeout in ms, 0 means no timeout
public Integer getExitStatus()
method).
- Returns:
- An
Integer holding the exit code, or
null if no exit code is (yet) available.
public String getExitSignal()
String holding the name of the signal, or
null if the process exited normally or is still
running (or if the server forgot to send this information).public void close()
close()
method, you may be wasting (local) resources.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||