com.mindbright.ssh
public class SSHClient extends SSH implements NIOCallback
SSHClientUser
-interface. The
authentication can be done in different ways, all which is handled through an
object implementing the SSHAuthenticator
-interface. The
console-output of the SSHClient
is (optionally) handled through
an object implementing the SSHConsole
-interface.
A class realizing a full interactive ssh-client is
SSHInteractiveClient
.
SSHAuthenticator
,
SSHClientUser
,
SSHConsole
Modifier and Type | Class and Description |
---|---|
static class |
SSHClient.AuthFailException |
static class |
SSHClient.ExitMonitor |
static class |
SSHClient.LocalForward |
static class |
SSHClient.RemoteForward |
Modifier and Type | Field and Description |
---|---|
protected boolean |
activateTunnels |
protected SSHAuthenticator |
authenticator |
protected java.lang.String |
commandLine |
protected SSHConsole |
console |
protected SSHChannelController |
controller |
protected java.lang.Object |
controllerMonitor |
protected java.lang.Integer |
exitStatus
Exit code.
|
protected int |
firstFTPPort |
protected boolean |
gracefulExit |
protected boolean |
havePORTFtp |
protected com.mindbright.ssh.SSHClient.KeepAliveThread |
heartbeat |
protected SSHInteractor |
interactor |
protected boolean |
isConnected |
protected boolean |
isOpened |
boolean |
isReading
SSHClient will set this variable to true when it is reading
from the input connection.
|
protected java.net.InetAddress |
localAddr |
protected java.util.Vector<SSHClient.LocalForward> |
localForwards |
protected SecureRandomAndPad |
rand |
protected int |
refCount |
protected java.util.Vector<SSHClient.RemoteForward> |
remoteForwards |
protected java.net.InetAddress |
serverAddr |
protected java.net.InetAddress |
serverRealAddr |
protected int |
srvVersionMajor |
protected int |
srvVersionMinor |
protected java.lang.String |
srvVersionStr |
protected NonBlockingInput |
sshIn |
protected NonBlockingOutput |
sshOut |
protected NetworkConnection |
sshSocket |
protected SSHClientUser |
user |
AUTH_CRYPTOCARD, AUTH_DEFAULT, AUTH_GSSAPI, AUTH_HOSTBASED, AUTH_KBDINTERACT, AUTH_KERBEROS, AUTH_NOTSUPPORTED, AUTH_PASSWORD, AUTH_PUBLICKEY, AUTH_RHOSTS, AUTH_RHOSTS_RSA, AUTH_SDI, AUTH_TIS, authTypeDesc, CIPHER_3DES, CIPHER_ANY, CIPHER_BLOWFISH, CIPHER_DEFAULT, CIPHER_DES, CIPHER_IDEA, CIPHER_INVALID, CIPHER_NONE, CIPHER_NOTSUPPORTED, CIPHER_RC4, CIPHER_RESERVED, CIPHER_TSS, cipherClasses, cipherType, CMSG_ACM_ACCESS_DENIED, CMSG_ACM_NEW_PIN, CMSG_ACM_NEW_PIN_ACCEPTED, CMSG_ACM_NEW_PIN_REJECTED, CMSG_ACM_NEW_PIN_REQUIRED, CMSG_ACM_NEXT_CODE, CMSG_ACM_NEXT_CODE_REQUIRED, CMSG_ACM_OK, CMSG_AGENT_REQUEST_FORWARDING, CMSG_AUTH_PASSWORD, CMSG_AUTH_RHOSTS, CMSG_AUTH_RHOSTS_RSA, CMSG_AUTH_RSA, CMSG_AUTH_RSA_RESPONSE, CMSG_AUTH_SDI, CMSG_AUTH_TIS, CMSG_AUTH_TIS_RESPONSE, CMSG_EOF, CMSG_EXEC_CMD, CMSG_EXEC_SHELL, CMSG_EXIT_CONFIRMATION, CMSG_MAX_PACKET_SIZE, CMSG_PORT_FORWARD_REQUEST, CMSG_REQUEST_COMPRESSION, CMSG_REQUEST_PTY, CMSG_SESSION_KEY, CMSG_STDIN_DATA, CMSG_USER, CMSG_WINDOW_SIZE, CMSG_X11_REQUEST_FORWARDING, CONNECT_CHAN_NUM, DEBUG, DEBUGMORE, DEBUGPKG, DEFAULTPORT, HOST_KEY_LENGTH, IDX_CIPHER_CLASS, IDX_CIPHER_NAME, isAnSSHClient, KNOWN_HOSTS_FILE, LISTEN_CHAN_NUM, MAIN_CHAN_NUM, MSG_ANY, MSG_CHANNEL_CLOSE, MSG_CHANNEL_CLOSE_CONFIRMATION, MSG_CHANNEL_DATA, MSG_CHANNEL_INPUT_EOF, MSG_CHANNEL_OPEN_CONFIRMATION, MSG_CHANNEL_OPEN_FAILURE, MSG_CHANNEL_OUTPUT_CLOSED, MSG_DEBUG, MSG_DISCONNECT, MSG_IGNORE, MSG_NONE, MSG_PORT_OPEN, PASS_KERBEROS_TGT, protocolFlags, PROTOFLAG_HOST_IN_FWD_OPEN, PROTOFLAG_SCREEN_NUMBER, PROXY_HTTP, PROXY_NONE, PROXY_NOTSUPPORTED, PROXY_SOCKS4, PROXY_SOCKS5_DNS, PROXY_SOCKS5_IP, rcvCipher, rcvComp, secureRandom, SERVER_KEY_LENGTH, SESSION_KEY_LENGTH, sessionId, sessionKey, SMSG_AGENT_OPEN, SMSG_AUTH_RSA_CHALLENGE, SMSG_AUTH_TIS_CHALLENGE, SMSG_EXITSTATUS, SMSG_FAILURE, SMSG_PUBLIC_KEY, SMSG_STDERR_DATA, SMSG_STDOUT_DATA, SMSG_SUCCESS, SMSG_X11_OPEN, sndCipher, sndComp, SRV_HOSTKEY_CHANGED, SRV_HOSTKEY_KNOWN, SRV_HOSTKEY_NEW, srvCookie, srvHostKey, srvServerKey, SSH_VER_MAJOR, SSH_VER_MINOR, supportedAuthTypes, supportedCiphers, TTY_OP_END, TTY_OP_ISPEED, TTY_OP_OSPEED, UNKNOWN_CHAN_NUM, VER_MINDTERM, VER_MINDTUNL
Constructor and Description |
---|
SSHClient(SSHAuthenticator authenticator,
SSHClientUser user) |
Modifier and Type | Method and Description |
---|---|
void |
addLocalPortForward(int localPort,
java.lang.String remoteHost,
int remotePort,
java.lang.String plugin) |
void |
addLocalPortForward(java.lang.String localHost,
int localPort,
java.lang.String remoteHost,
int remotePort,
java.lang.String plugin) |
int |
addRef() |
void |
addRemotePortForward(java.lang.String remoteHost,
int remotePort,
java.lang.String localHost,
int localPort,
java.lang.String plugin) |
protected void |
boot(boolean haveCnxWatch,
NetworkConnection tpSocket) |
void |
bootSSH(boolean haveCnxWatch) |
void |
bootSSH(boolean haveCnxWatch,
boolean releaseConnection) |
void |
clearAllForwards() |
void |
completed(java.nio.ByteBuffer buf)
Called once the network read operation has been completed
|
void |
connected(boolean timeout)
Called once the connection has been established (assuming
interest for this has been registered by calling the
NotifyWhenConnected method of Switchboard ). |
void |
connectionFailed(java.lang.Exception e)
Called if the connection failed (assuming
interest for this has been registered by calling the
NotifyWhenConnected method of Switchboard ). |
void |
delLocalPortForward(java.lang.String localHost,
int port) |
int |
delRef() |
void |
delRemotePortForward(java.lang.String plugin) |
void |
delRemotePortForward(java.lang.String remoteHost,
int port) |
protected void |
disconnect(boolean graceful) |
protected void |
disconnect(boolean graceful,
java.lang.Exception e) |
void |
doSingleCommand(java.lang.String commandLine,
boolean background,
long msTimeout) |
void |
forcedDisconnect() |
long |
getConnectTimeout() |
SSHConsole |
getConsole() |
java.lang.Exception |
getException() |
java.lang.Integer |
getExitStatus()
Returns the exit status if it was set or null otherwise.
|
long |
getHelloTimeout() |
java.net.InetAddress |
getLocalAddr() |
java.net.InetAddress |
getServerAddr() |
java.net.InetAddress |
getServerRealAddr() |
java.lang.String |
getServerVersion() |
boolean |
isConnected() |
boolean |
isOpened() |
void |
readFailed(java.lang.Exception e)
Called if the read failed
|
void |
requestLocalPortForward(java.lang.String localHost,
int localPort,
java.lang.String remoteHost,
int remotePort,
java.lang.String plugin) |
void |
setConsole(SSHConsole console) |
protected void |
setExitStatus(int status)
Called from SSHChannelController to set the exit status.
|
void |
setLocalAddr(java.lang.String addr) |
void |
setServerRealAddr(java.net.InetAddress realAddr) |
protected void |
shutdown(java.lang.Exception e)
Shut down the connection
|
void |
startExitMonitor() |
void |
startExitMonitor(long msTimeout) |
void |
waitForExit() |
void |
waitForExit(long msTimeout) |
void |
writeFailed()
Called if the write failed
|
getAltAuthName, getAuthName, getAuthType, getAuthTypes, getCipherName, getCipherType, getProxyType, getProxyTypes, getSupportedCipher, getVersionId, initCipher, initClientCipher, initServerCipher, isAuthTypeSupported, isProtocolFlagSet, log, logDebug, logExtra, logIgnore, msgTypeString, secureRandom
protected com.mindbright.ssh.SSHClient.KeepAliveThread heartbeat
protected SecureRandomAndPad rand
protected java.net.InetAddress serverAddr
protected java.net.InetAddress serverRealAddr
protected java.net.InetAddress localAddr
protected java.lang.String srvVersionStr
protected int srvVersionMajor
protected int srvVersionMinor
protected java.util.Vector<SSHClient.LocalForward> localForwards
protected java.util.Vector<SSHClient.RemoteForward> remoteForwards
protected java.lang.String commandLine
protected java.lang.Object controllerMonitor
protected SSHChannelController controller
protected SSHConsole console
protected SSHAuthenticator authenticator
protected SSHClientUser user
protected SSHInteractor interactor
protected NetworkConnection sshSocket
protected NonBlockingInput sshIn
protected NonBlockingOutput sshOut
protected boolean gracefulExit
protected boolean isConnected
protected boolean isOpened
protected int refCount
protected boolean havePORTFtp
protected int firstFTPPort
protected boolean activateTunnels
public boolean isReading
protected java.lang.Integer exitStatus
public SSHClient(SSHAuthenticator authenticator, SSHClientUser user)
public java.lang.Exception getException()
public void setConsole(SSHConsole console)
public SSHConsole getConsole()
public java.net.InetAddress getServerAddr()
public java.net.InetAddress getServerRealAddr()
public void setServerRealAddr(java.net.InetAddress realAddr)
public java.net.InetAddress getLocalAddr()
public void setLocalAddr(java.lang.String addr) throws java.net.UnknownHostException
java.net.UnknownHostException
public java.lang.String getServerVersion()
public void addLocalPortForward(int localPort, java.lang.String remoteHost, int remotePort, java.lang.String plugin) throws java.io.IOException
java.io.IOException
public void addLocalPortForward(java.lang.String localHost, int localPort, java.lang.String remoteHost, int remotePort, java.lang.String plugin) throws java.io.IOException
java.io.IOException
public void delLocalPortForward(java.lang.String localHost, int port)
public void addRemotePortForward(java.lang.String remoteHost, int remotePort, java.lang.String localHost, int localPort, java.lang.String plugin)
public void delRemotePortForward(java.lang.String remoteHost, int port)
public void delRemotePortForward(java.lang.String plugin)
public void clearAllForwards()
public void startExitMonitor()
public void startExitMonitor(long msTimeout)
public int addRef()
public void forcedDisconnect()
public int delRef()
public void waitForExit()
public void waitForExit(long msTimeout)
public void doSingleCommand(java.lang.String commandLine, boolean background, long msTimeout) throws java.io.IOException
java.io.IOException
public long getConnectTimeout()
public long getHelloTimeout()
public void bootSSH(boolean haveCnxWatch) throws java.io.IOException
java.io.IOException
public void bootSSH(boolean haveCnxWatch, boolean releaseConnection) throws java.io.IOException
java.io.IOException
protected void boot(boolean haveCnxWatch, NetworkConnection tpSocket)
protected void setExitStatus(int status)
public java.lang.Integer getExitStatus()
protected void disconnect(boolean graceful)
protected void disconnect(boolean graceful, java.lang.Exception e)
public void requestLocalPortForward(java.lang.String localHost, int localPort, java.lang.String remoteHost, int remotePort, java.lang.String plugin) throws java.io.IOException
java.io.IOException
public boolean isOpened()
public boolean isConnected()
protected void shutdown(java.lang.Exception e)
public void completed(java.nio.ByteBuffer buf)
NIOCallback
completed
in interface NIOCallback
buf
- the buffer provided to the read callpublic void readFailed(java.lang.Exception e)
NIOCallback
readFailed
in interface NIOCallback
public void writeFailed()
NIOCallback
writeFailed
in interface NIOCallback
public void connected(boolean timeout)
NIOCallback
NotifyWhenConnected
method of Switchboard
).connected
in interface NIOCallback
timeout
- true if the connection attempt timed outpublic void connectionFailed(java.lang.Exception e)
NIOCallback
NotifyWhenConnected
method of Switchboard
).connectionFailed
in interface NIOCallback
e
- the exception the connection failed with.