AdventNet CLI 2.0 API Specification

com.adventnet.cli.transport.ssh
Class SshProtocolOptionsImpl

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

public class SshProtocolOptionsImpl
extends java.lang.Object
implements CLIProtocolOptions, java.io.Serializable

This class provides the SSH implementation of the CLIProtocolOptions interface. It contains parameters like the Remote Host Address, Port, login parameters, etc. In order to establish a CLI session over SSH with a particular device the appropriate parameters has to be set on an instance of this class and passed to the CLISession's constructor. A subsequent call to the open() method in CLISession will establish the Telnet connection based on the parameters set here.

 
 CLISession session = new CLISession(cliProtocolOptionsImpl,enablePooling);
 session.open();
  
OR it can be set on the session before calling the open() method in the CLISession, like:
 session.setCLIProtocolOptions(cliProtocolOptionsImpl);
 
where session is an instance of CLISession and cliProtcolOptionsImpl is an instance of the class which implements this interface. The enablePooling is a boolean to indicate whether the session is dedicated or not.

See Also:
Serialized Form

Constructor Summary
SshProtocolOptionsImpl()
          Constructs ProtocolOptions for secure Telnet Connection.
 
Method Summary
 java.lang.Object clone()
          Returns an exact copy of this object.
 java.lang.Object getID()
          Gets the Key based on the combination of remoteHost, Port and login name.
 java.lang.String getInitialMessage()
          Gets the initial message sent by the device after a connection is established.
 java.lang.String getLoginName()
          Gets the login Name.
 int getLoginTimeout()
          Gets the login timeout of the ssh connection.
 java.lang.String getPassword()
          Gets the login Password.
 java.lang.String getPrompt()
          Gets the Prompt.
 java.lang.String getRemoteHost()
          Gets the Remote Host name or IP address.
 int getRemotePort()
          Gets the Remote Port.
 java.lang.String getTerminalType()
          Gets the current terminal type.
 void setInitialMessage(java.lang.String message)
          Sets the initial message sent by the device after a connection is established.
 void setLoginName(java.lang.String loginName)
          Sets the login Name.
 void setLoginTimeout(int timeout)
          Sets the login timeout.
 void setPassword(java.lang.String passwd)
          Sets the login Password.
 void setPrompt(java.lang.String prompt)
          Sets the Prompt.
 void setRemoteHost(java.lang.String remoteHost)
          Sets the Remote Host name or IP address in dotted format.
 void setRemotePort(int remotePort)
          Sets the Remote Port.
 void setTerminalType(java.lang.String terminal)
          Sets the terminal type of the remote machine.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshProtocolOptionsImpl

public SshProtocolOptionsImpl()
Constructs ProtocolOptions for secure Telnet Connection. Contains the RemoteHost/RemotePort and other parameters. This class contains all the parameters that are needed for opening a secure telnet/SSH connection to a device.

For example to set various protocol options the following can be done:

 
 SshProtocolOptionsImpl protocolOptions = new SshProtocolOptionsImpl()
 protocolOptions.setRemoteHost("localhost");
 protocolOptions.setRemotePort(22);
 protocolOptions.setLoginName("guest");
 protocolOptions.setPassword("guest");
 protocolOptions.setPrompt("$");

 

This will be the parameters to open a secure telnet connection to the localhost on port 22 (the standard telnet port). The login user and password will be 'guest' and the prompt that would be expected will be '$'. Here the login prompt and password prompt are assumed as "login:" and "Password:" respectively. Command can be set on the CLIMessage and sent to the corresponding device using CLISession like:


 CLISession cliSess = new CLISession(protocolOptions);
 cliSess.setTransportProviderClassName("com.adventnet.cli.ssh.SshTransportProviderImpl");
 cliSess.open();
 CLIMessage msg = new CLIMessage("date");
 System.out.println(cliSess.syncSend(msg).getData());
 

Where cliSess is an instance of an open CLISession. This will send the CLI message to the appropriate device based on the above parameters set. Note that the transport provider implementation class name can be set in /conf/cliTransport.conf file or using the API CLISession.setTransportProviderClassName(String).
Method Detail

setRemoteHost

public void setRemoteHost(java.lang.String remoteHost)
Sets the Remote Host name or IP address in dotted format.
Parameters:
remoteHost - the remoteHost to connect.

getRemoteHost

public java.lang.String getRemoteHost()
Gets the Remote Host name or IP address.
Returns:
the remoteHost.

setRemotePort

public void setRemotePort(int remotePort)
Sets the Remote Port.
Parameters:
remotePort - the remotePort to connect with.

getRemotePort

public int getRemotePort()
Gets the Remote Port.
Returns:
the remotePort.

getID

public java.lang.Object getID()
Gets the Key based on the combination of remoteHost, Port and login name. The API user need not call this method. It is internally used by the API.
Specified by:
getID in interface CLIProtocolOptions
Returns:
returns the ID as an Object.

setLoginName

public void setLoginName(java.lang.String loginName)
Sets the login Name. For devices which do not prompt for a login name, this parameter need not be set or can be set as null.
Parameters:
loginName - the login user Name for the connection.

getLoginName

public java.lang.String getLoginName()
Gets the login Name.
Returns:
the login Name.

setPassword

public void setPassword(java.lang.String passwd)
Sets the login Password. For devices which do not prompt for a Password, this parameter need not be set or can be set as null.
Parameters:
passwd - the login Password.

getPassword

public java.lang.String getPassword()
Gets the login Password.
Returns:
the login Password.

setPrompt

public void setPrompt(java.lang.String prompt)
Sets the Prompt. This is the String that is issued by the device after a successful login. Usually this is also sent back by the device after the execution of each command.
Parameters:
prompt - the command prompt.

getPrompt

public java.lang.String getPrompt()
Gets the Prompt. This is the String that is issued by the device after a successful login.
Returns:
the command prompt as a String instance.

setTerminalType

public void setTerminalType(java.lang.String terminal)
Sets the terminal type of the remote machine. This is sent to the remote server during the SSH protocol negotiation.
Parameters:
terminalType - the terminal that the remote machine emulates such as vt100, vt320 or others as a String value.

getTerminalType

public java.lang.String getTerminalType()
Gets the current terminal type.
Returns:
the terminal type as a String value.

clone

public java.lang.Object clone()
Returns an exact copy of this object.
Specified by:
clone in interface CLIProtocolOptions
Overrides:
clone in class java.lang.Object
Returns:
copy of this object.

getInitialMessage

public java.lang.String getInitialMessage()
Gets the initial message sent by the device after a connection is established.
Specified by:
getInitialMessage in interface CLIProtocolOptions
Returns:
the initial login message from the device.

setInitialMessage

public void setInitialMessage(java.lang.String message)
Sets the initial message sent by the device after a connection is established. Implementors of this interface should set the initial message sent by the device after a successful connection establishment.
Specified by:
setInitialMessage in interface CLIProtocolOptions
Parameters:
message - the login Message from the device.

getLoginTimeout

public int getLoginTimeout()
Gets the login timeout of the ssh connection. This is the time for which the CLISession tries to do a successful login. If this time expires, the session throws an Exception.
Returns:
the login timeout in milliseconds.

setLoginTimeout

public void setLoginTimeout(int timeout)
Sets the login timeout. During login if this timeout expires, an exception is thrown.
Parameters:
timeout - the timeout in milliseconds.

AdventNet CLI 2.0 API Specification