|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Base interface for SSH sessions supporting all the features common to both SSH1 and SSH2.
Sessions are created through the openSessionChannel()
method of the SshClient. Once a session has been obtained the session
will not be active until you either call executeCommand(String command)
or startShell(). Once activated you can use the IO streams to read and write
to the remote process. The following code shows the basic process:
SshConnector con = SshConnector.getInstance();
SshClient ssh = con.connect(
new SocketTransport("beagle2.3sp.net", 22),
"martianx");
PasswordAuthentication pwd = new PasswordAuthentication();
pwd.setPassword("likeidgivethataway!");
if(ssh.authenticate(pwd)==SshAuthentication.COMPLETE) {
SshSession sesison = ssh.openSessionChannel();
if(session.requestPseudoTerminal("vt100",
80,
24,
0,
0)) {
session.startShell();
session.getOutputStream().write("ls\n".getBytes());
}
} else {
System.out.println("Authentication failed");
}
Ssh1Session
,
Ssh2Session
Field Summary | |
static int |
EXITCODE_NOT_RECEIVED
Returned from exitCode() when the remote process is still active. |
Method Summary | |
void |
changeTerminalDimensions(int cols,
int rows,
int width,
int height)
Change the dimensions of the terminal window. |
void |
close()
Close the session. |
boolean |
executeCommand(java.lang.String cmd)
Execute a command. |
boolean |
executeCommand(java.lang.String cmd,
java.lang.String charset)
Execute a command. |
int |
exitCode()
Return the exit code of the process once complete. |
SshClient |
getClient()
Get the client that created this session. |
java.io.InputStream |
getInputStream()
Get an InputStream to read the process stdout. |
java.io.OutputStream |
getOutputStream()
Get an OutputStream to write to the process stdin. |
java.io.InputStream |
getStderrInputStream()
Get an InputStream to read the process stderr. |
boolean |
isClosed()
Evaluate whether the channel is closed. |
boolean |
requestPseudoTerminal(java.lang.String term,
int cols,
int rows,
int width,
int height)
The remote process may require a pseudo terminal. |
boolean |
requestPseudoTerminal(java.lang.String term,
int cols,
int rows,
int width,
int height,
byte[] modes)
The remote process may require a pseudo terminal. |
boolean |
requestPseudoTerminal(java.lang.String term,
int cols,
int rows,
int width,
int height,
PseudoTerminalModes terminalModes)
The remote process may require a pseudo terminal. |
boolean |
startShell()
Start the users default shell. |
Methods inherited from interface com.maverick.ssh.SshChannel |
addChannelEventListener, getChannelId, setAutoConsumeInput |
Field Detail |
public static final int EXITCODE_NOT_RECEIVED
Method Detail |
public boolean startShell() throws SshException
true
if the shell was started, otherwise
false
SshException
public SshClient getClient()
public boolean executeCommand(java.lang.String cmd) throws SshException
cmd
-
true
if the command was accepted, otherwise
false
. This may not return false if the
command is incorrect, it should only be used as an
indication that the command was accepted and that the
server will attempt to execute it.
SshException
public boolean executeCommand(java.lang.String cmd, java.lang.String charset) throws SshException
cmd
-
true
if the command was accepted, otherwise
false
. This may not return false if the
command is incorrect, it should only be used as an
indication that the command was accepted and that the
server will attempt to execute it.
SshException
public boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height, byte[] modes) throws SshException
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)modes
- an array of encoded terminal modes as described in the
SSH protocol specifications.
true
if the pty was allocated, otherwise false
SshException
public boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height, PseudoTerminalModes terminalModes) throws SshException
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)terminalModes
- the known terminal modes
true
if the pty was allocated, otherwise false
SshException
public boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height) throws SshException
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)
true
if the pty was allocated, otherwise false
SshException
public java.io.InputStream getInputStream() throws SshIOException
getInputStream
in interface SshIO
SshException
SshIOException
public java.io.OutputStream getOutputStream() throws SshIOException
getOutputStream
in interface SshIO
SshException
SshIOException
public java.io.InputStream getStderrInputStream() throws SshIOException
SshException
SshIOException
public void close()
close
in interface SshIO
public int exitCode()
public void changeTerminalDimensions(int cols, int rows, int width, int height) throws SshException
cols
- rows
- width
- height
-
SshException
public boolean isClosed()
isClosed
in interface SshChannel
true
if the session is closed, otherwise false
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |