SSH Factory

com.jscape.inet.ssh
Class Ssh

java.lang.Object
  extended by com.jscape.inet.ssh.Ssh

public class Ssh
extends java.lang.Object

Implements the basic functionality of a SSH2 (Secure Shell) client.

Example Usage:

 public class SshExample implements SshListener {
 

// state of SSH connection private boolean connected = false;

public SshExample() { String hostname = null; String username = null; String password = null; Ssh ssh = null;

try { BufferedReader bin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter SSH hostname: "); hostname = bin.readLine();

System.out.print("Enter SSH username: "); username = bin.readLine();

System.out.print("Enter SSH password: "); password = bin.readLine();

// create new SshParameters instance SshParameters sshParams = new SshParameters(hostname,username,password);

// create new Ssh instance ssh = new Ssh(sshParams);

// register to capture events ssh.addSshListener(this);

System.out.println("Connecting please wait...");

// connect ssh.connect();

// get output stream for writing data to SSH server OutputStream out = ssh.getOutputStream();

// holds line entered at console String line = null;

// read data from console while (connected && (line = bin.readLine()) != null) { // send line with LF to SSH server line += "\n"; try { out.write(line.getBytes()); out.flush(); } catch(Exception ioe){ connected = false; } } } catch (Exception e) { e.printStackTrace(); } finally { try { if(connected) { ssh.disconnect(); } } catch(Exception e) {

} } }

// captures SshConnectedEvent public void connected(SshConnectedEvent ev) { System.out.println("Connected: " + ev.getHost()); connected = true; }

// captures SshDataReceivedEvent public void dataReceived(SshDataReceivedEvent ev) { // send data received to console System.out.print(ev.getData()); }

// captures SshDisconnectedEvent event public void disconnected(SshDisconnectedEvent ev) { System.out.println("Disconnected: " + ev.getHost() + ". Press Enter to exit"); connected = false; } }

Version:
1.0
Author:
vglass

Field Summary
static java.lang.String AUTH_METHOD_HOSTBASE
           
static java.lang.String AUTH_METHOD_KBI
           
static java.lang.String AUTH_METHOD_NONE
           
static java.lang.String AUTH_METHOD_PASSWORD
           
static java.lang.String AUTH_METHOD_PUBLICKEY
           
static java.lang.String CHANNEL_REQUEST_ENV
           
static java.lang.String CHANNEL_REQUEST_EXEC
           
static java.lang.String CHANNEL_REQUEST_EXIT_SIGNAL
           
static java.lang.String CHANNEL_REQUEST_EXIT_STATUS
           
static java.lang.String CHANNEL_REQUEST_PTY_REQ
           
static java.lang.String CHANNEL_REQUEST_SHELL
           
static java.lang.String CHANNEL_REQUEST_SIGNAL
           
static java.lang.String CHANNEL_REQUEST_SUBSYSTEM
           
static java.lang.String CHANNEL_REQUEST_WINDOW_CHANGE
           
static java.lang.String CHANNEL_REQUEST_X11_REQ
           
static java.lang.String CHANNEL_REQUEST_XON_XOFF
           
static java.lang.String CHANNEL_TYPE_DIRECT_TCPIP
           
static java.lang.String CHANNEL_TYPE_FORWARDED_TCPIP
           
static java.lang.String CHANNEL_TYPE_SESSION
           
static java.lang.String CHANNEL_TYPE_X11
           
static java.lang.String COMPRESSION_ALG_NONE
           
static java.lang.String COMPRESSION_ALG_ZLIB
           
static java.lang.String DEFAULT_TYPE
           
static int DISCONNECT_AUTH_CANCELLED_BY_USER
           
static int DISCONNECT_BY_APPLICATION
           
static int DISCONNECT_COMPRESSION_ERROR
           
static int DISCONNECT_CONNECTION_LOST
           
static int DISCONNECT_HOST_KEY_NOT_VERIFIABLE
           
static int DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT
           
static int DISCONNECT_ILLEGAL_USER_NAME
           
static int DISCONNECT_KEY_EXCHANGE_FAILED
           
static int DISCONNECT_MAC_ERROR
           
static int DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE
           
static int DISCONNECT_PROTOCOL_ERROR
           
static int DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED
           
static int DISCONNECT_RESERVED
           
static int DISCONNECT_SERVICE_NOT_AVAILABLE
           
static int DISCONNECT_TOO_MANY_CONNECTIONS
           
static java.lang.String ENCRYPTION_ALG_3DES_CBC
           
static java.lang.String ENCRYPTION_ALG_AES128_CBC
           
static java.lang.String ENCRYPTION_ALG_AES192_CBC
           
static java.lang.String ENCRYPTION_ALG_AES256_CBC
           
static java.lang.String ENCRYPTION_ALG_ARCFOUR
           
static java.lang.String ENCRYPTION_ALG_BLOWFISH_CBC
           
static java.lang.String ENCRYPTION_ALG_CAST128_CBC
           
static java.lang.String ENCRYPTION_ALG_DES_CBC
           
static java.lang.String ENCRYPTION_ALG_IDEA_CBC
           
static java.lang.String ENCRYPTION_ALG_NONE
           
static java.lang.String ENCRYPTION_ALG_SERPENT128_CBC
           
static java.lang.String ENCRYPTION_ALG_SERPENT192_CBC
           
static java.lang.String ENCRYPTION_ALG_SERPENT256_CBC
           
static java.lang.String ENCRYPTION_ALG_TWOFISH_CBC
           
static java.lang.String ENCRYPTION_ALG_TWOFISH128_CBC
           
static java.lang.String ENCRYPTION_ALG_TWOFISH192_CBC
           
static java.lang.String ENCRYPTION_ALG_TWOFISH256_CBC
           
static java.lang.String KEY_EXCHANGE_DIFFIE_HELLMAN
           
static java.lang.String MAC_ALG_HMAC_MD5
           
static java.lang.String MAC_ALG_HMAC_MD5_96
           
static java.lang.String MAC_ALG_HMAC_SHA1
           
static java.lang.String MAC_ALG_HMAC_SHA1_96
           
static java.lang.String MAC_ALG_NONE
           
static int MSG_CHANNEL_CLOSE
           
static int MSG_CHANNEL_DATA
           
static int MSG_CHANNEL_EOF
           
static int MSG_CHANNEL_EXTENDED_DATA
           
static int MSG_CHANNEL_FAILURE
           
static int MSG_CHANNEL_OPEN
           
static int MSG_CHANNEL_OPEN_CONFIRMATION
           
static int MSG_CHANNEL_OPEN_FAILURE
           
static int MSG_CHANNEL_REQUEST
           
static int MSG_CHANNEL_SUCCESS
           
static int MSG_CHANNEL_WINDOW_ADJUST
           
static int MSG_DEBUG
           
static int MSG_DISCONNECT
           
static int MSG_GLOBAL_REQUEST
           
static int MSG_IGNORE
           
static int MSG_KEXDH_INIT
           
static int MSG_KEXDH_REPLY
           
static int MSG_KEXINIT
           
static int MSG_NEWKEYS
           
static int MSG_REQUEST_FAILURE
           
static int MSG_REQUEST_SUCCESS
           
static int MSG_SERVICE_ACCEPT
           
static int MSG_SERVICE_REQUEST
           
static int MSG_UNIMPLEMENTED
           
static int MSG_USERAUTH_BANNER
           
static int MSG_USERAUTH_FAILURE
           
static int MSG_USERAUTH_PK_OK
           
static int MSG_USERAUTH_REQUEST
           
static int MSG_USERAUTH_SUCCESS
           
static java.lang.String PROTOCOL_REQUEST_TCPIP_FORWARD
           
static java.lang.String PROTOCOL_REQUEST_TCPIP_FORWARD_CANCEL
           
static java.lang.String PUB_KEY_ALG_PGP_SIGN_DSS
           
static java.lang.String PUB_KEY_ALG_PGP_SIGN_RSA
           
static java.lang.String PUB_KEY_ALG_SPKI_SIGN_DSS
           
static java.lang.String PUB_KEY_ALG_SPKI_SIGN_RSA
           
static java.lang.String PUB_KEY_ALG_SSH_DSS
           
static java.lang.String PUB_KEY_ALG_SSH_RSA
           
static java.lang.String PUB_KEY_ALG_X509V3_SIGN_DSS
           
static java.lang.String PUB_KEY_ALG_X509V3_SIGN_RSA
           
static java.lang.String SERVICE_CONNECTION
           
static java.lang.String SERVICE_USERAUTH
           
 
Constructor Summary
Ssh(SshParameters sshParams)
          Constructs a new Ssh instance
Ssh(SshParameters sshParams, SshConfiguration config)
          Constructs a new Ssh instance.
Ssh(java.lang.String host, int port, java.lang.String user)
          Constructs a new Ssh instance.
Ssh(java.lang.String host, int port, java.lang.String user, java.lang.String password)
          Constructs a new Ssh instance.
Ssh(java.lang.String host, int port, java.lang.String user, java.lang.String password, SshConfiguration config)
          Constructs a new Ssh instance.
Ssh(java.lang.String host, java.lang.String user)
          Constructs a new Ssh instance.
Ssh(java.lang.String host, java.lang.String user, java.lang.String password)
          Consructs a new Ssh instance.
 
Method Summary
 void addSshListener(SshListener listener)
          Add SSH event listener.
 void connect()
          Connects to SSH server.
 void disconnect()
          Closes open connection.
 java.lang.String getCharacterSet()
          Gets the character set
 boolean getDebug()
          Gets whether debugging is enabled.
 java.io.PrintStream getDebugStream()
          Gets PrintStream used in reporting debug statements.
 boolean getEcho()
          Returns echo flag.
 SshHostKeys getHostKeys()
          Returns SSH host keys for further use.
 java.lang.String getHostname()
          Return server hostname.
 java.io.InputStream getInputStream()
          Returns connection input stream.
 java.io.OutputStream getOutputStream()
          Returns connection output stream.
 int getPort()
          Return server port.
 long getReadTimeout()
          Returns current read timeout value.
 long getTimeout()
          Gets the timeout for opening connection to SSH server.
 boolean isConnected()
          Checks if the current client is connected.
 boolean isInitReader()
          Gets if reader should be initialized automatically or if will be created by user.
 void removeSshListener(SshListener listener)
          Remove SSH event listener.
 void requestExec(java.lang.String command)
          Method requestExec request the SSH server to start the execution of the given command.
 void requestTerminalWindowChange(int widthChars, int heightChars, int widthPixels, int heightPixels)
          Requests terminal window change on the server side.
 void setCharacterSet(java.lang.String encoding)
          Sets character set used when reading data using ssh
 void setDebug(boolean debug)
          Enable debugging output to debugging stream.
 void setDebugStream(java.io.PrintStream debugStream)
          Sets PrintStream used in reporting debug statements.
 void setEcho(boolean echo)
          Sets server echo flag for the next connection.
 void setInitReader(boolean initReader)
          Sets if reader should be initialized automatically or if will be created by user.
 void setReadTimeout(long readTimeout)
          Sets read timeout value.
 void setTerminalType(java.lang.String terminalType)
          Sets terminal type emulation to use for this SSH session.
 void setTimeout(long timeout)
          Sets the timeout for opening connection to SSH server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MSG_DISCONNECT

public static final int MSG_DISCONNECT
See Also:
Constant Field Values

MSG_IGNORE

public static final int MSG_IGNORE
See Also:
Constant Field Values

MSG_UNIMPLEMENTED

public static final int MSG_UNIMPLEMENTED
See Also:
Constant Field Values

MSG_DEBUG

public static final int MSG_DEBUG
See Also:
Constant Field Values

MSG_SERVICE_REQUEST

public static final int MSG_SERVICE_REQUEST
See Also:
Constant Field Values

MSG_SERVICE_ACCEPT

public static final int MSG_SERVICE_ACCEPT
See Also:
Constant Field Values

MSG_KEXINIT

public static final int MSG_KEXINIT
See Also:
Constant Field Values

MSG_NEWKEYS

public static final int MSG_NEWKEYS
See Also:
Constant Field Values

MSG_KEXDH_INIT

public static final int MSG_KEXDH_INIT
See Also:
Constant Field Values

MSG_KEXDH_REPLY

public static final int MSG_KEXDH_REPLY
See Also:
Constant Field Values

MSG_USERAUTH_REQUEST

public static final int MSG_USERAUTH_REQUEST
See Also:
Constant Field Values

MSG_USERAUTH_FAILURE

public static final int MSG_USERAUTH_FAILURE
See Also:
Constant Field Values

MSG_USERAUTH_SUCCESS

public static final int MSG_USERAUTH_SUCCESS
See Also:
Constant Field Values

MSG_USERAUTH_BANNER

public static final int MSG_USERAUTH_BANNER
See Also:
Constant Field Values

MSG_USERAUTH_PK_OK

public static final int MSG_USERAUTH_PK_OK
See Also:
Constant Field Values

MSG_GLOBAL_REQUEST

public static final int MSG_GLOBAL_REQUEST
See Also:
Constant Field Values

MSG_REQUEST_SUCCESS

public static final int MSG_REQUEST_SUCCESS
See Also:
Constant Field Values

MSG_REQUEST_FAILURE

public static final int MSG_REQUEST_FAILURE
See Also:
Constant Field Values

MSG_CHANNEL_OPEN

public static final int MSG_CHANNEL_OPEN
See Also:
Constant Field Values

MSG_CHANNEL_OPEN_CONFIRMATION

public static final int MSG_CHANNEL_OPEN_CONFIRMATION
See Also:
Constant Field Values

MSG_CHANNEL_OPEN_FAILURE

public static final int MSG_CHANNEL_OPEN_FAILURE
See Also:
Constant Field Values

MSG_CHANNEL_WINDOW_ADJUST

public static final int MSG_CHANNEL_WINDOW_ADJUST
See Also:
Constant Field Values

MSG_CHANNEL_DATA

public static final int MSG_CHANNEL_DATA
See Also:
Constant Field Values

MSG_CHANNEL_EXTENDED_DATA

public static final int MSG_CHANNEL_EXTENDED_DATA
See Also:
Constant Field Values

MSG_CHANNEL_EOF

public static final int MSG_CHANNEL_EOF
See Also:
Constant Field Values

MSG_CHANNEL_CLOSE

public static final int MSG_CHANNEL_CLOSE
See Also:
Constant Field Values

MSG_CHANNEL_REQUEST

public static final int MSG_CHANNEL_REQUEST
See Also:
Constant Field Values

MSG_CHANNEL_SUCCESS

public static final int MSG_CHANNEL_SUCCESS
See Also:
Constant Field Values

MSG_CHANNEL_FAILURE

public static final int MSG_CHANNEL_FAILURE
See Also:
Constant Field Values

DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT

public static final int DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT
See Also:
Constant Field Values

DISCONNECT_PROTOCOL_ERROR

public static final int DISCONNECT_PROTOCOL_ERROR
See Also:
Constant Field Values

DISCONNECT_KEY_EXCHANGE_FAILED

public static final int DISCONNECT_KEY_EXCHANGE_FAILED
See Also:
Constant Field Values

DISCONNECT_RESERVED

public static final int DISCONNECT_RESERVED
See Also:
Constant Field Values

DISCONNECT_MAC_ERROR

public static final int DISCONNECT_MAC_ERROR
See Also:
Constant Field Values

DISCONNECT_COMPRESSION_ERROR

public static final int DISCONNECT_COMPRESSION_ERROR
See Also:
Constant Field Values

DISCONNECT_SERVICE_NOT_AVAILABLE

public static final int DISCONNECT_SERVICE_NOT_AVAILABLE
See Also:
Constant Field Values

DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED

public static final int DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED
See Also:
Constant Field Values

DISCONNECT_HOST_KEY_NOT_VERIFIABLE

public static final int DISCONNECT_HOST_KEY_NOT_VERIFIABLE
See Also:
Constant Field Values

DISCONNECT_CONNECTION_LOST

public static final int DISCONNECT_CONNECTION_LOST
See Also:
Constant Field Values

DISCONNECT_BY_APPLICATION

public static final int DISCONNECT_BY_APPLICATION
See Also:
Constant Field Values

DISCONNECT_TOO_MANY_CONNECTIONS

public static final int DISCONNECT_TOO_MANY_CONNECTIONS
See Also:
Constant Field Values

DISCONNECT_AUTH_CANCELLED_BY_USER

public static final int DISCONNECT_AUTH_CANCELLED_BY_USER
See Also:
Constant Field Values

DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE

public static final int DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE
See Also:
Constant Field Values

DISCONNECT_ILLEGAL_USER_NAME

public static final int DISCONNECT_ILLEGAL_USER_NAME
See Also:
Constant Field Values

SERVICE_USERAUTH

public static final java.lang.String SERVICE_USERAUTH
See Also:
Constant Field Values

SERVICE_CONNECTION

public static final java.lang.String SERVICE_CONNECTION
See Also:
Constant Field Values

AUTH_METHOD_KBI

public static final java.lang.String AUTH_METHOD_KBI
See Also:
Constant Field Values

AUTH_METHOD_PUBLICKEY

public static final java.lang.String AUTH_METHOD_PUBLICKEY
See Also:
Constant Field Values

AUTH_METHOD_PASSWORD

public static final java.lang.String AUTH_METHOD_PASSWORD
See Also:
Constant Field Values

AUTH_METHOD_HOSTBASE

public static final java.lang.String AUTH_METHOD_HOSTBASE
See Also:
Constant Field Values

AUTH_METHOD_NONE

public static final java.lang.String AUTH_METHOD_NONE
See Also:
Constant Field Values

CHANNEL_TYPE_SESSION

public static final java.lang.String CHANNEL_TYPE_SESSION
See Also:
Constant Field Values

CHANNEL_TYPE_X11

public static final java.lang.String CHANNEL_TYPE_X11
See Also:
Constant Field Values

CHANNEL_TYPE_FORWARDED_TCPIP

public static final java.lang.String CHANNEL_TYPE_FORWARDED_TCPIP
See Also:
Constant Field Values

CHANNEL_TYPE_DIRECT_TCPIP

public static final java.lang.String CHANNEL_TYPE_DIRECT_TCPIP
See Also:
Constant Field Values

PROTOCOL_REQUEST_TCPIP_FORWARD

public static final java.lang.String PROTOCOL_REQUEST_TCPIP_FORWARD
See Also:
Constant Field Values

PROTOCOL_REQUEST_TCPIP_FORWARD_CANCEL

public static final java.lang.String PROTOCOL_REQUEST_TCPIP_FORWARD_CANCEL
See Also:
Constant Field Values

CHANNEL_REQUEST_PTY_REQ

public static final java.lang.String CHANNEL_REQUEST_PTY_REQ
See Also:
Constant Field Values

CHANNEL_REQUEST_X11_REQ

public static final java.lang.String CHANNEL_REQUEST_X11_REQ
See Also:
Constant Field Values

CHANNEL_REQUEST_ENV

public static final java.lang.String CHANNEL_REQUEST_ENV
See Also:
Constant Field Values

CHANNEL_REQUEST_SHELL

public static final java.lang.String CHANNEL_REQUEST_SHELL
See Also:
Constant Field Values

CHANNEL_REQUEST_EXEC

public static final java.lang.String CHANNEL_REQUEST_EXEC
See Also:
Constant Field Values

CHANNEL_REQUEST_SUBSYSTEM

public static final java.lang.String CHANNEL_REQUEST_SUBSYSTEM
See Also:
Constant Field Values

CHANNEL_REQUEST_WINDOW_CHANGE

public static final java.lang.String CHANNEL_REQUEST_WINDOW_CHANGE
See Also:
Constant Field Values

CHANNEL_REQUEST_XON_XOFF

public static final java.lang.String CHANNEL_REQUEST_XON_XOFF
See Also:
Constant Field Values

CHANNEL_REQUEST_SIGNAL

public static final java.lang.String CHANNEL_REQUEST_SIGNAL
See Also:
Constant Field Values

CHANNEL_REQUEST_EXIT_STATUS

public static final java.lang.String CHANNEL_REQUEST_EXIT_STATUS
See Also:
Constant Field Values

CHANNEL_REQUEST_EXIT_SIGNAL

public static final java.lang.String CHANNEL_REQUEST_EXIT_SIGNAL
See Also:
Constant Field Values

KEY_EXCHANGE_DIFFIE_HELLMAN

public static final java.lang.String KEY_EXCHANGE_DIFFIE_HELLMAN
See Also:
Constant Field Values

ENCRYPTION_ALG_3DES_CBC

public static final java.lang.String ENCRYPTION_ALG_3DES_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_BLOWFISH_CBC

public static final java.lang.String ENCRYPTION_ALG_BLOWFISH_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_TWOFISH256_CBC

public static final java.lang.String ENCRYPTION_ALG_TWOFISH256_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_TWOFISH_CBC

public static final java.lang.String ENCRYPTION_ALG_TWOFISH_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_TWOFISH192_CBC

public static final java.lang.String ENCRYPTION_ALG_TWOFISH192_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_TWOFISH128_CBC

public static final java.lang.String ENCRYPTION_ALG_TWOFISH128_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_AES256_CBC

public static final java.lang.String ENCRYPTION_ALG_AES256_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_AES192_CBC

public static final java.lang.String ENCRYPTION_ALG_AES192_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_AES128_CBC

public static final java.lang.String ENCRYPTION_ALG_AES128_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_SERPENT256_CBC

public static final java.lang.String ENCRYPTION_ALG_SERPENT256_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_SERPENT192_CBC

public static final java.lang.String ENCRYPTION_ALG_SERPENT192_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_SERPENT128_CBC

public static final java.lang.String ENCRYPTION_ALG_SERPENT128_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_ARCFOUR

public static final java.lang.String ENCRYPTION_ALG_ARCFOUR
See Also:
Constant Field Values

ENCRYPTION_ALG_IDEA_CBC

public static final java.lang.String ENCRYPTION_ALG_IDEA_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_CAST128_CBC

public static final java.lang.String ENCRYPTION_ALG_CAST128_CBC
See Also:
Constant Field Values

ENCRYPTION_ALG_NONE

public static final java.lang.String ENCRYPTION_ALG_NONE
See Also:
Constant Field Values

ENCRYPTION_ALG_DES_CBC

public static final java.lang.String ENCRYPTION_ALG_DES_CBC
See Also:
Constant Field Values

MAC_ALG_HMAC_SHA1

public static final java.lang.String MAC_ALG_HMAC_SHA1
See Also:
Constant Field Values

MAC_ALG_HMAC_SHA1_96

public static final java.lang.String MAC_ALG_HMAC_SHA1_96
See Also:
Constant Field Values

MAC_ALG_HMAC_MD5

public static final java.lang.String MAC_ALG_HMAC_MD5
See Also:
Constant Field Values

MAC_ALG_HMAC_MD5_96

public static final java.lang.String MAC_ALG_HMAC_MD5_96
See Also:
Constant Field Values

MAC_ALG_NONE

public static final java.lang.String MAC_ALG_NONE
See Also:
Constant Field Values

PUB_KEY_ALG_SSH_DSS

public static final java.lang.String PUB_KEY_ALG_SSH_DSS
See Also:
Constant Field Values

PUB_KEY_ALG_SSH_RSA

public static final java.lang.String PUB_KEY_ALG_SSH_RSA
See Also:
Constant Field Values

PUB_KEY_ALG_X509V3_SIGN_RSA

public static final java.lang.String PUB_KEY_ALG_X509V3_SIGN_RSA
See Also:
Constant Field Values

PUB_KEY_ALG_X509V3_SIGN_DSS

public static final java.lang.String PUB_KEY_ALG_X509V3_SIGN_DSS
See Also:
Constant Field Values

PUB_KEY_ALG_SPKI_SIGN_RSA

public static final java.lang.String PUB_KEY_ALG_SPKI_SIGN_RSA
See Also:
Constant Field Values

PUB_KEY_ALG_SPKI_SIGN_DSS

public static final java.lang.String PUB_KEY_ALG_SPKI_SIGN_DSS
See Also:
Constant Field Values

PUB_KEY_ALG_PGP_SIGN_RSA

public static final java.lang.String PUB_KEY_ALG_PGP_SIGN_RSA
See Also:
Constant Field Values

PUB_KEY_ALG_PGP_SIGN_DSS

public static final java.lang.String PUB_KEY_ALG_PGP_SIGN_DSS
See Also:
Constant Field Values

COMPRESSION_ALG_NONE

public static final java.lang.String COMPRESSION_ALG_NONE
See Also:
Constant Field Values

COMPRESSION_ALG_ZLIB

public static final java.lang.String COMPRESSION_ALG_ZLIB
See Also:
Constant Field Values

DEFAULT_TYPE

public static final java.lang.String DEFAULT_TYPE
See Also:
Constant Field Values
Constructor Detail

Ssh

public Ssh(SshParameters sshParams,
           SshConfiguration config)
Constructs a new Ssh instance.

Parameters:
sshParams - the SSH connection parameters
config - the SSH protocol configuration

Ssh

public Ssh(SshParameters sshParams)
Constructs a new Ssh instance

Parameters:
sshParams - SSH connection parameters

Ssh

public Ssh(java.lang.String host,
           int port,
           java.lang.String user,
           java.lang.String password,
           SshConfiguration config)
Constructs a new Ssh instance.

Parameters:
host - the SSH server hostname
port - the SSH server port
user - the SSH server username
password - the SSH server password
config - the SSH protocol configuration

Ssh

public Ssh(java.lang.String host,
           int port,
           java.lang.String user,
           java.lang.String password)
Constructs a new Ssh instance.

Parameters:
host - the SSH server hostname
port - the SSH server port
user - the SSH server username
password - the SSH server password

Ssh

public Ssh(java.lang.String host,
           int port,
           java.lang.String user)
Constructs a new Ssh instance.

Parameters:
host - SSH host
port - SSH port
user - SSH username

Ssh

public Ssh(java.lang.String host,
           java.lang.String user,
           java.lang.String password)
Consructs a new Ssh instance.

Parameters:
host - the SSH host
user - the SSH user
password - the SSH password

Ssh

public Ssh(java.lang.String host,
           java.lang.String user)
Constructs a new Ssh instance.

Parameters:
host - SSH host
user - SSH username
Method Detail

getHostname

public java.lang.String getHostname()
Return server hostname.

Returns:
the hostname or IP address of the SSH server

getPort

public int getPort()
Return server port.

Returns:
the port of the SSH server

isInitReader

public boolean isInitReader()
Gets if reader should be initialized automatically or if will be created by user. By default reader is initialized automatically during connect().

Returns:
true if reader initialized automatically, false otherwise

setInitReader

public void setInitReader(boolean initReader)
Sets if reader should be initialized automatically or if will be created by user. By default reader is initialized automatically during connect().

Parameters:
initReader - true to initialize reader, false otherwise

addSshListener

public void addSshListener(SshListener listener)
Add SSH event listener.

Parameters:
listener - a SshListener
See Also:
SshListener

removeSshListener

public void removeSshListener(SshListener listener)
Remove SSH event listener.

Parameters:
listener - a SshListener
See Also:
SshListener

setDebug

public void setDebug(boolean debug)
Enable debugging output to debugging stream. Default debugging stream is System.out.

Parameters:
debug - true if debugging is enabled
See Also:
setDebugStream(java.io.PrintStream)

getDebug

public boolean getDebug()
Gets whether debugging is enabled. Default debugging stream is System.out.

Returns:
true if debugging is enabled, false otherwise
See Also:
setDebugStream(PrintStream)

getDebugStream

public java.io.PrintStream getDebugStream()
Gets PrintStream used in reporting debug statements. Default PrintStream is System.out.

Returns:
the PrintStream used in reporting debug statements
See Also:
PrintStream

setDebugStream

public void setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements. Default PrintStream is System.out.

Parameters:
debugStream - the PrintStream to send debug statements to
See Also:
PrintStream

setTerminalType

public void setTerminalType(java.lang.String terminalType)
Sets terminal type emulation to use for this SSH session. An example terminal type is vt100, default is "dumb".

Parameters:
terminalType - the terminal type

getEcho

public boolean getEcho()
Returns echo flag.

Returns:
true if server echo is enabled; false otherwise

setEcho

public void setEcho(boolean echo)
Sets server echo flag for the next connection.

Parameters:
echo - if true server echo will be enabled for the next connection.

getTimeout

public long getTimeout()
Gets the timeout for opening connection to SSH server.

Returns:
timeout in milliseconds

setTimeout

public void setTimeout(long timeout)
Sets the timeout for opening connection to SSH server.

Parameters:
timeout - the timeout in milliseconds

getReadTimeout

public long getReadTimeout()
Returns current read timeout value.

Returns:
current read timeout value

setReadTimeout

public void setReadTimeout(long readTimeout)
Sets read timeout value. Must be greater or equal to 0. A value of 0 indicates an infinite timeout.

Parameters:
readTimeout - read timeout value in milliseconds.

getHostKeys

public SshHostKeys getHostKeys()
Returns SSH host keys for further use.

Returns:
SSH host keys or null if keys are not available

setCharacterSet

public void setCharacterSet(java.lang.String encoding)
Sets character set used when reading data using ssh

Parameters:
encoding - the encoding name

getCharacterSet

public java.lang.String getCharacterSet()
Gets the character set

Returns:
The character set used by the service

isConnected

public boolean isConnected()
Checks if the current client is connected.

Returns:
true if the client is connected; false otherwise

connect

public void connect()
             throws SshException
Connects to SSH server.

Throws:
SshException - if an I/O error occurs.

disconnect

public void disconnect()
Closes open connection.


getInputStream

public java.io.InputStream getInputStream()
Returns connection input stream.

Returns:
connection input stream.

getOutputStream

public java.io.OutputStream getOutputStream()
Returns connection output stream.

Returns:
connection output stream.

requestExec

public void requestExec(java.lang.String command)
                 throws SshException
Method requestExec request the SSH server to start the execution of the given command. The command string may contain a path.

Parameters:
command - String command for execution.
Throws:
SshException - if error occurs

requestTerminalWindowChange

public void requestTerminalWindowChange(int widthChars,
                                        int heightChars,
                                        int widthPixels,
                                        int heightPixels)
                                 throws SshException
Requests terminal window change on the server side.

Parameters:
widthChars - window width in chars
heightChars - window heigth in chars
widthPixels - window width in pixels
heightPixels - window height in pixels
Throws:
SshException - if an error occurs

SSH Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved