public class SSHSession extends java.lang.Object implements Transport
NetconfSession intends
to use SSH for its transport. This class uses the Ganymed SSH
implementation. (http://www.ganymed
.ethz.ch/ssh2/)
Example:
SSHConnection c = new SSHConnection("127.0.0.1", 789);
c.authenticateWithPassword("ola", "secret");
SSHSession ssh = new SSHSession(c);
NetconfSession dev1 = new NetconfSession(ssh);
| Modifier and Type | Field and Description |
|---|---|
protected long |
readTimeout |
| Constructor and Description |
|---|
SSHSession(SSHConnection con)
Constructor for SSH session object.
|
SSHSession(SSHConnection con,
long readTimeout)
Constructor with an extra argument for a readTimeout timer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSubscriber(IOSubscriber s)
Add an IO Subscriber for this transport.
|
void |
close()
Closes the SSH channnel
|
void |
delSubscriber(IOSubscriber s)
Removes an IO subscriber.
|
void |
flush()
Signals that the final chunk of data has be printed to the output
transport stream.
|
long |
getReadTimeout()
Return the readTimeout value that is used to read data from the ssh
socket.
|
Session |
getSession()
Needed by users that need to monitor a session for EOF .
|
SSHConnection |
getSSHConnection()
Return the underlying ssh connection object
|
void |
print(int iVal)
Prints an integer (as text) to the output stream.
|
void |
print(java.lang.String s)
Prints text to the output stream.
|
void |
println(int iVal)
Prints an integer (as text) to the output stream.
|
void |
println(java.lang.String s)
Print text to the output stream.
|
java.lang.StringBuffer |
readOne()
Reads in "one" reply from the SSH transport input 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 |
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
|
public SSHSession(SSHConnection con) throws java.io.IOException, JNCException
con - an established and authenticated SSH connectionjava.io.IOExceptionJNCExceptionpublic SSHSession(SSHConnection con, long readTimeout) throws java.io.IOException, JNCException
con - readTimeout - Time to wait for read. (in milliseconds)java.io.IOExceptionJNCExceptionpublic SSHConnection getSSHConnection()
public long getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout - timout 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 java.io.IOException
ready in interface Transportjava.io.IOExceptionpublic boolean serverSideClosed()
throws java.io.IOException
java.io.IOExceptionpublic int readUntilWouldBlock()
public java.lang.StringBuffer readOne()
throws java.io.IOException,
JNCException
readOne in interface Transportjava.io.IOExceptionJNCExceptionpublic void print(int iVal)
public void print(java.lang.String s)
public void println(int iVal)
public void println(java.lang.String s)
public void addSubscriber(IOSubscriber s)
s - An IOSUbscriber that will be called whenever there is something
received or sent on this transport.public void delSubscriber(IOSubscriber s)
s - The IO subscriber to remove.public void flush()
A ]]>]]> character sequence is added, as described in RFC 4742, to signal that the last part of the reply has been sent.
public 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