public class SSHSession extends Object implements CliSession
Example:
SSHConnection c = new SSHConnection("127.0.0.1", 22); c.authenticateWithPassword("ola", "secret"); SSHSession ssh = new SSHSession(c);
Constructor and Description |
---|
SSHSession(ch.ethz.ssh2.Connection con)
Deprecated.
|
SSHSession(ch.ethz.ssh2.Connection con,
int readTimeout,
NedTracer tracer,
NedConnectionBase conn)
Deprecated.
|
SSHSession(ch.ethz.ssh2.Connection con,
int readTimeout,
NedTracer tracer,
NedConnectionBase conn,
int width,
int height)
Deprecated.
|
SSHSession(ch.ethz.ssh2.Connection con,
NedTracer tracer,
NedConnectionBase conn)
Deprecated.
|
SSHSession(SSHConnection con)
Constructor for SSH session object.
|
SSHSession(SSHConnection con,
int readTimeout,
NedTracer tracer,
NedConnectionBase conn)
Constructor with an extra argument for a readTimeout timer.
|
SSHSession(SSHConnection con,
int readTimeout,
NedTracer tracer,
NedConnectionBase conn,
int width,
int height)
Constructor with extra terminal width and height arguments
|
SSHSession(SSHConnection con,
NedTracer tracer,
NedConnectionBase conn)
Constructor for SSH session object.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the SSH connection, including all sessions (only one in
this case, compared to many in Netconf)
|
String |
expect(Pattern p) |
NedExpectResult |
expect(Pattern[] p) |
NedExpectResult |
expect(Pattern[] p,
boolean include,
int timeout) |
NedExpectResult |
expect(Pattern[] p,
boolean include,
int timeout,
boolean full) |
NedExpectResult |
expect(Pattern[] p,
boolean include,
int timeout,
boolean full,
NedWorker worker) |
NedExpectResult |
expect(Pattern[] p,
boolean include,
int timeout,
NedWorker worker) |
NedExpectResult |
expect(Pattern[] p,
NedWorker worker) |
String |
expect(Pattern p,
boolean include,
int timeout) |
String |
expect(Pattern p,
boolean include,
int timeout,
NedWorker worker) |
String |
expect(Pattern p,
NedWorker worker) |
String |
expect(String Str)
Read from socket until Pattern is encountered.
|
NedExpectResult |
expect(String[] Str) |
NedExpectResult |
expect(String[] Str,
boolean include,
int timeout) |
NedExpectResult |
expect(String[] Str,
boolean include,
int timeout,
NedWorker worker) |
NedExpectResult |
expect(String[] Str,
NedWorker worker) |
String |
expect(String str,
boolean include,
boolean full,
int timeout)
Read from socket until Pattern is encountered.
|
String |
expect(String str,
boolean include,
boolean full,
int timeout,
NedWorker worker) |
String |
expect(String Str,
boolean Include,
int timeout)
Read from socket until Pattern is encountered.
|
String |
expect(String Str,
boolean Include,
int timeout,
NedWorker worker) |
String |
expect(String Str,
int timeout)
Read from socket until Pattern is encountered.
|
String |
expect(String Str,
int timeout,
NedWorker worker) |
String |
expect(String Str,
NedWorker worker) |
String |
expectStr(String Str,
boolean include,
int timeout)
Read from socket until Pattern is encountered.
|
void |
flush()
Signals that the final chunk of data has be printed to the output
transport stream.
|
int |
getReadTimeout()
Return the readTimeout value that is used to read data from
the ssh socket.
|
ch.ethz.ssh2.Session |
getSession()
Needed by users that need to monitor a session for EOF .
|
ch.ethz.ssh2.Connection |
getSSHConnection()
Return the underlying ssh connection object
|
void |
print(int iVal)
Prints an integer (as text) to the output stream.
|
void |
print(String s)
Prints text to the output stream.
|
void |
println(int iVal)
Prints an integer (as text) to the output stream.
|
void |
println(String s)
Print text to the output stream.
|
int |
readUntilWouldBlock()
If we have readTimeout set, and an outstanding operation was
timed out - the socket may still be alive.
|
boolean |
ready()
Tell whether this transport is ready to be read.
|
boolean |
ready(int timeout) |
boolean |
serverSideClosed()
given a live SSHSession, check if the server side has
closed it's end of the ssh socket
|
void |
setReadTimeout(int readTimeout)
Set the read timeout
|
void |
setTracer(NedTracer tracer) |
public SSHSession(SSHConnection con) throws IOException
con
- an established and authenticated SSH connectionIOException
@Deprecated public SSHSession(ch.ethz.ssh2.Connection con) throws IOException
con
- an established and authenticated SSH connectionIOException
public SSHSession(SSHConnection con, NedTracer tracer, NedConnectionBase conn) throws IOException
con
- an established and authenticated SSH connectiontracer
- Ned tracerconn
- NedConnection objectIOException
@Deprecated public SSHSession(ch.ethz.ssh2.Connection con, NedTracer tracer, NedConnectionBase conn) throws IOException
IOException
public SSHSession(SSHConnection con, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException
con
- an established and authenticated SSH connectionreadTimeout
- timeout in millisecondstracer
- Ned Tracerconn
- NedConnection objectIOException
@Deprecated public SSHSession(ch.ethz.ssh2.Connection con, int readTimeout, NedTracer tracer, NedConnectionBase conn) throws IOException
con
- readTimeout
- Time to wait for read. (in milliseconds)IOException
public SSHSession(SSHConnection con, int readTimeout, NedTracer tracer, NedConnectionBase conn, int width, int height) throws IOException
con
- an established and authenticated SSH connectionreadTimeout
- timeout in millisecondstracer
- Ned Tracerconn
- NedConnection objectwidth
- Terminal width (in characters)height
- Terminal height (in characters)IOException
@Deprecated public SSHSession(ch.ethz.ssh2.Connection con, int readTimeout, NedTracer tracer, NedConnectionBase conn, int width, int height) throws IOException
con
- readTimeout
- Time to wait for read. (in milliseconds)width
- Terminal width (in characters)height
- Terminal height (in characters)IOException
public ch.ethz.ssh2.Connection getSSHConnection()
public int getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout
- timeout in milliseconds
The readTimeout parameter affects all read operations. If a timeout
is reached, an INMException is thrown. The socket is not closed.public boolean ready() throws IOException
IOException
public boolean ready(int timeout) throws IOException
IOException
public boolean serverSideClosed()
serverSideClosed
in interface CliSession
public int readUntilWouldBlock()
public String expectStr(String Str, boolean include, int timeout) throws SSHSessionException, IOException
Str
- is a string which is match against each line read.include
- controls if the pattern should be include
in the returned string or not.SSHSessionException
IOException
public String expect(String Str) throws SSHSessionException, IOException
expect
in interface CliSession
Str
- is a regular expression pattern which is match against
each line read.SSHSessionException
IOException
public String expect(Pattern p) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public String expect(String Str, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public String expect(Pattern p, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public String expect(String Str, int timeout) throws SSHSessionException, IOException
expect
in interface CliSession
Str
- is a regular expression pattern which is match against
each line read.timeout
- indicates the read timeoutSSHSessionException
IOException
public String expect(String Str, int timeout, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public String expect(String Str, boolean Include, int timeout) throws SSHSessionException, IOException
expect
in interface CliSession
Str
- is a regular expression pattern which is match against
each line read.Include
- controls if the pattern should be include
in the returned string or not.SSHSessionException
IOException
public String expect(Pattern p, boolean include, int timeout) throws SSHSessionException, IOException
SSHSessionException
IOException
public NedExpectResult expect(String[] Str) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(String[] Str, boolean include, int timeout) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p, boolean include, int timeout) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public String expect(String Str, boolean Include, int timeout, NedWorker worker) throws SSHSessionException, IOException
SSHSessionException
IOException
public String expect(Pattern p, boolean include, int timeout, NedWorker worker) throws SSHSessionException, IOException
SSHSessionException
IOException
public NedExpectResult expect(String[] Str, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(String[] Str, boolean include, int timeout, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, boolean full) throws SSHSessionException, IOException
SSHSessionException
IOException
public NedExpectResult expect(Pattern[] p, boolean include, int timeout, boolean full, NedWorker worker) throws SSHSessionException, IOException
SSHSessionException
IOException
public String expect(String str, boolean include, boolean full, int timeout) throws IOException, SSHSessionException
expect
in interface CliSession
str
- is a regular expression pattern which is match against
each line read.include
- controls if the pattern should be include
in the returned string or not.full
- controls if the pattern should be matched against
the entire line, or if a positive match is accepted whenever the
pattern matches any substring on a line.IOException
SSHSessionException
public String expect(String str, boolean include, boolean full, int timeout, NedWorker worker) throws SSHSessionException, IOException
expect
in interface CliSession
SSHSessionException
IOException
public void print(int iVal)
iVal
- Text to send to the stream.public void print(String s)
print
in interface CliSession
s
- Text to send to the stream.public void println(int iVal)
iVal
- Text to send to the stream.public void println(String s)
println
in interface CliSession
s
- Text to send to the stream.public void flush()
flush
in interface CliSession
public ch.ethz.ssh2.Session getSession()
int conditionSet = ChannelCondition.TIMEOUT ;amp ChannelCondition.CLOSED ;amp ChannelCondition.EOF; conditionSet = s.waitForCondition(conditionSet, 1); if (conditionSet != ChannelCondition.TIMEOUT) { // We know the server closed it's end of the ssh // socket
public void setTracer(NedTracer tracer)
setTracer
in interface CliSession
public void close()
close
in interface CliSession