AdventNet CLI 2.0 API Specification

com.adventnet.cli.transport.ssh
Class SshTransportProviderImpl

java.lang.Object
  |
  +--com.adventnet.cli.transport.ssh.SshTransportProviderImpl

public class SshTransportProviderImpl
extends java.lang.Object
implements CLITransportProvider

The SSH implementation of the CLITransportProvider for communicating with the remote host using ssh.

Since:
CLI2.0sp4
See Also:
CLITransportProvider

Fields inherited from interface com.adventnet.cli.transport.CLITransportProvider
STREAM_CLOSED
 
Constructor Summary
SshTransportProviderImpl()
          Creates an instance of ssh provider.
 
Method Summary
 void close()
          This closes the SSH connection to the remote device.
 void connect(java.lang.String host, int port)
          Connects to the remote host.
 double getSshVersion(java.lang.String host, int port)
          Gets the SSH version of the remote SSH server.
 java.lang.String login(java.lang.String userName, java.lang.String password, java.lang.String prompt)
          Logs into the remote host with username and password.
 void open(CLIProtocolOptions cliProtOpt)
          Opens a SSH connection to the remote device.
 CLIMessage read()
          Receives the CLI message from the opened telnet connection.
 int read(byte[] b)
          Reads data from the socket ( as byte stream).
 void setSocketTimeout(int timeout)
          sets the socket timeout value.
 void write(byte[] b)
          Sends command or byte stream to the remote host.
 void write(CLIMessage cliMsg)
          Sends the command in the CLIMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshTransportProviderImpl

public SshTransportProviderImpl()
Creates an instance of ssh provider. API users need not instantiate this class since it is instantiated internally by CLIResourceManager.
Method Detail

open

public void open(CLIProtocolOptions cliProtOpt)
          throws java.lang.Exception,
                 ConnectException,
                 LoginException
Opens a SSH connection to the remote device. Parameters like the Remote Host, Port, Login name and password are taken from the CLIProtocolOptions parameter that is passed to the method.

The login prompt and password prompt are assumed as "login:" and "Password:" and the login to the remote host will succeed only if the prompt returned by the device matches with the above.

Specified by:
open in interface CLITransportProvider
Parameters:
cliProtOpt - the CLIProtocolOptions with the parameters.
Throws:
java.lang.Exception - thrown when an error occurs while trying to telnet to the remote device.
ConnectException - if unable to connect to the specified host and port.
LoginException - if any of the login parameters like username and password is incorrect.

close

public void close()
           throws java.lang.Exception
This closes the SSH connection to the remote device.
Specified by:
close in interface CLITransportProvider
Throws:
java.lang.Exception - if any error occurs during the closing of the connection.

write

public void write(CLIMessage cliMsg)
           throws java.io.IOException
Sends the command in the CLIMessage. The CLI command to be sent will be present in a byte array in the CLIMessage argument.
Specified by:
write in interface CLITransportProvider
Parameters:
cliMsg - the CLIMessage that has to be sent. The CLI command (as a string) is obtained by calling cliMsg.getData().
Throws:
java.io.IOException - if error occurs while writing the data.

read

public CLIMessage read()
                throws java.io.IOException
Receives the CLI message from the opened telnet connection. The CLI response is read into the CLIMessage and returned.
Specified by:
read in interface CLITransportProvider
Returns:
CLIMessage that is read.
Throws:
java.io.IOException - if error occurs while reading the data through the telnet connection.

getSshVersion

public double getSshVersion(java.lang.String host,
                            int port)
Gets the SSH version of the remote SSH server. defaults to version 1.99 incase an exception occurs during the process.
Parameters:
host - the remote ssh server.
port - the port in which the ssh server listens.
Returns:
the ssh verison as a double value

connect

public void connect(java.lang.String host,
                    int port)
             throws ConnectException
Connects to the remote host.
Parameters:
host - the remote host name
port - the remote port
Throws:
ConnectException - if an error occurs

login

public java.lang.String login(java.lang.String userName,
                              java.lang.String password,
                              java.lang.String prompt)
                       throws java.io.IOException
Logs into the remote host with username and password.
Parameters:
userName - the user name
password - the password for authentication
prompt - shell prompt as a string.
Returns:
the login message
Throws:
java.io.IOException - if an error occurs

setSocketTimeout

public void setSocketTimeout(int timeout)
                      throws java.io.IOException
sets the socket timeout value. The login or command will timeout after this interval.
Parameters:
timeout - an int value
Throws:
java.io.IOException - if an error occurs

write

public void write(byte[] b)
           throws java.io.IOException
Sends command or byte stream to the remote host.
Parameters:
b - a byte[] value
Throws:
java.io.IOException - if an error occurs

read

public int read(byte[] b)
         throws java.io.IOException
Reads data from the socket ( as byte stream).
Parameters:
b - a byte[] value
Returns:
the number of bytes read as an int value
Throws:
java.io.IOException - if an error occurs

AdventNet CLI 2.0 API Specification