public class Session extends Object implements Runnable
Channel
s of various
types, created with openChannel(java.lang.String)
.
A session is opened with connect()
and closed with
disconnect()
.
Modifier and Type | Field and Description |
---|---|
protected boolean |
daemon_thread |
Modifier and Type | Method and Description |
---|---|
void |
connect()
opens the connection, using the timeout set with
setTimeout(int) . |
void |
connect(int connectTimeout)
opens the connection, using the specified timeout.
|
void |
delPortForwardingL(int lport)
Cancels the local port forwarding assigned
at local TCP port
lport on loopback interface. |
void |
delPortForwardingL(String bind_address,
int lport)
Cancels the local port forwarding assigned
at local TCP port
lport on bind_address interface. |
void |
delPortForwardingR(int rport)
Cancels the remote port forwarding assigned at remote TCP port
rport . |
void |
delPortForwardingR(String bind_address,
int rport)
Cancels the remote port forwarding assigned at
remote TCP port
rport bound on the interface at
bind_address . |
void |
disconnect()
Closes the connection to the server.
|
void |
encode(Packet packet)
(not to be invoked from outside)
|
String |
getClientVersion()
returns the version string (to be) sent to the server.
|
String |
getConfig(String key)
Retrieves a configuration option of this session.
|
String |
getHost()
gets the host name to which we will connect (or are connected).
|
HostKey |
getHostKey()
retrieves the host key of the server.
|
String |
getHostKeyAlias()
retrieves the current server host key alias.
|
HostKeyRepository |
getHostKeyRepository()
Gets the hostkeyRepository.
|
int |
getPort()
returns the port at the remote host we will connect
(or already connected) to.
|
String[] |
getPortForwardingL()
returns a snapshot of the current local port forwarding
configurations.
|
String[] |
getPortForwardingR()
Lists the registered remote port forwarding.
|
int |
getServerAliveCountMax()
Returns setting for the threshold to send keep-alive messages.
|
int |
getServerAliveInterval()
Returns setting for the interval to send a keep-alive message.
|
String |
getServerVersion()
returns the version string sent by the server.
|
Channel |
getStreamForwarder(String host,
int port)
Instantiates an instance of stream-forwarder to
host :port . |
int |
getTimeout()
retrieves the current timeout setting.
|
UserInfo |
getUserInfo()
returns the current value of the UserInfo object.
|
String |
getUserName()
returns the user name used for login (and set when creating the session).
|
boolean |
isConnected()
retrieves the current connection status.
|
void |
noMoreSessionChannels() |
Channel |
openChannel(String type)
Opens a new channel of some type over this connection.
|
Buffer |
read(Buffer buf)
reads some bytes - not to be used from outside.
|
void |
rekey()
initiates a new key exchange.
|
void |
run()
Not to be called from outside.
|
void |
sendIgnore()
sends an ignored package.
|
void |
sendKeepAliveMsg()
Sends a keep-alive message.
|
void |
setClientVersion(String cv)
changes the version string to be sent to the server.
|
void |
setConfig(Hashtable newconf)
sets several configuration options at once.
|
void |
setConfig(Properties newconf)
sets several configuration options at once.
|
void |
setConfig(String key,
String value)
sets a single configuration option for this session.
|
void |
setDaemonThread(boolean enable)
Sets the deamon thread property.
|
void |
setHost(String host)
Sets the host to connect to.
|
void |
setHostKeyAlias(String hostKeyAlias)
sets the host key alias used when comparing the
host key to the known hosts list.
|
void |
setHostKeyRepository(HostKeyRepository hostkeyRepository)
Sets the hostkeyRepository, which will be referred in checking host keys.
|
void |
setIdentityRepository(IdentityRepository identityRepository)
Sets the identityRepository, which will be referred
in the public key authentication.
|
void |
setInputStream(InputStream in)
(I have no idea what this is for.
|
void |
setOutputStream(OutputStream out)
(I have no idea what this is for.
|
void |
setPassword(byte[] password)
sets the password to use for authentication.
|
void |
setPassword(String password)
sets the password to use for authentication.
|
void |
setPort(int port)
Sets the port on the server to connect to.
|
int |
setPortForwardingL(int lport,
String host,
int rport)
Registers the local port forwarding for loop-back interface.
|
int |
setPortForwardingL(String conf)
Registers the local port forwarding.
|
int |
setPortForwardingL(String bind_address,
int lport,
String host,
int rport)
Registers the local port forwarding.
|
int |
setPortForwardingL(String bind_address,
int lport,
String host,
int rport,
ServerSocketFactory ssf)
Registers the local port forwarding.
|
int |
setPortForwardingL(String bind_address,
int lport,
String host,
int rport,
ServerSocketFactory ssf,
int connectTimeout)
Registers the local port forwarding.
|
void |
setPortForwardingR(int rport,
String daemon)
Registers the remote port forwarding for the loopback interface
of the remote.
|
void |
setPortForwardingR(int rport,
String host,
int lport)
Registers the remote port forwarding for the loopback interface
of the remote.
|
void |
setPortForwardingR(int rport,
String host,
int lport,
SocketFactory sf)
Registers the remote port forwarding for the loopback interface
of the remote.
|
void |
setPortForwardingR(int rport,
String daemon,
Object[] arg)
Registers the remote port forwarding for the loopback interface
of the remote.
|
int |
setPortForwardingR(String conf)
Registers the remote port forwarding.
|
void |
setPortForwardingR(String bind_address,
int rport,
String host,
int lport)
Registers the remote port forwarding.
|
void |
setPortForwardingR(String bind_address,
int rport,
String host,
int lport,
SocketFactory sf)
Registers the remote port forwarding.
|
void |
setPortForwardingR(String bind_address,
int rport,
String daemon,
Object[] arg)
Registers the remote port forwarding.
|
void |
setProxy(Proxy proxy)
Sets the proxy property.
|
void |
setServerAliveCountMax(int count)
Sets the number of keep-alive messages which may be sent without
receiving any messages back from the server.
|
void |
setServerAliveInterval(int interval)
sets the server alive interval property.
|
void |
setSocketFactory(SocketFactory sfactory)
sets the socket factory.
|
void |
setTimeout(int timeout)
sets the timeout setting.
|
void |
setUserInfo(UserInfo userinfo)
Sets the userInfo property.
|
void |
setX11Cookie(String cookie)
sets the X11 cookie necessary to access the local X11 server.
|
void |
setX11Host(String host)
sets the host (on the local side) where the X11 server
(whose display we want to forward) can be found.
|
void |
setX11Port(int port)
sets the port (on the local side) where the X11 server
(whose display we want to forward) can be found.
|
void |
write(Packet packet)
Not to be used from outside - Writes a packet.
|
public void connect() throws JSchException
setTimeout(int)
.JSchException
- if this session is already connected.connect(int)
public void connect(int connectTimeout) throws JSchException
JSchException
- if this session is already connected, or some
other error occurs during connecting. (If there was some other
exception, it is appended as the cause to the JSchException thrown.)public void rekey() throws Exception
Exception
public Channel openChannel(String type) throws JSchException
type
- a string identifying the channel type. For now,
the available types are these: shell
- ChannelShell
exec
- ChannelExec
direct-tcpip
- ChannelDirectTCPIP
sftp
- ChannelSftp
subsystem
- ChannelSubsystem
forwarded-tcpip
- ChannelForwardedTCPIP
session
x11
auth-agent@openssh.com
JSchException
public void encode(Packet packet) throws Exception
Exception
public Buffer read(Buffer buf) throws Exception
Exception
public void write(Packet packet) throws Exception
Exception
public void run()
public void disconnect()
public int setPortForwardingL(int lport, String host, int rport) throws JSchException
lport
is 0
, the tcp port will be allocated.lport
- local port for local port forwardinghost
- host address for local port forwardingrport
- remote port number for local port forwardingJSchException
setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
public int setPortForwardingL(String bind_address, int lport, String host, int rport) throws JSchException
bind_address
is an empty string
or '*', the port should be available from all interfaces.
If bind_address
is "localhost"
or
null
, the listening port will be bound for local use only.
If lport
is 0
, the tcp port will be allocated.bind_address
- bind address for local port forwardinglport
- local port for local port forwardinghost
- host address for local port forwardingrport
- remote port number for local port forwardingJSchException
setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf) throws JSchException
bind_address
is an empty string or "*"
,
the port should be available from all interfaces.
If bind_address
is "localhost"
or
null
, the listening port will be bound for local use only.
If lport
is 0
, the tcp port will be allocated.bind_address
- bind address for local port forwardinglport
- local port for local port forwardinghost
- host address for local port forwardingrport
- remote port number for local port forwardingssf
- socket factoryJSchException
setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) throws JSchException
bind_address
is an empty string
or "*"
, the port should be available from all interfaces.
If bind_address
is "localhost"
or
null
, the listening port will be bound for local use only.
If lport
is 0
, the tcp port will be allocated.bind_address
- bind address for local port forwardinglport
- local port for local port forwardinghost
- host address for local port forwardingrport
- remote port number for local port forwardingssf
- socket factoryconnectTimeout
- timeout for establishing port connectionJSchException
public void delPortForwardingL(int lport) throws JSchException
lport
on loopback interface.lport
- local TCP portJSchException
public void delPortForwardingL(String bind_address, int lport) throws JSchException
lport
on bind_address
interface.bind_address
- bind_address of network interfaceslport
- local TCP portJSchException
public String[] getPortForwardingL() throws JSchException
localport:remotehost:remoteportwith the numbers in decimal representation.
JSchException
public void setPortForwardingR(int rport, String host, int lport) throws JSchException
rport
- remote porthost
- host addresslport
- local portJSchException
setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
public void setPortForwardingR(String bind_address, int rport, String host, int lport) throws JSchException
bind_address
is an empty string or "*"
,
the port should be available from all interfaces.
If bind_address
is "localhost"
or is not given,
the listening port will be bound for local use only.
Note that if GatewayPorts
is "no"
on the
remote, "localhost"
is always used as a bind_address.bind_address
- bind addressrport
- remote porthost
- host addresslport
- local portJSchException
setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
public void setPortForwardingR(int rport, String host, int lport, SocketFactory sf) throws JSchException
rport
- remote porthost
- host addresslport
- local portsf
- socket factoryJSchException
setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
public void setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf) throws JSchException
bind_address
is an empty string or "*"
,
the port should be available from all interfaces.
If bind_address
is "localhost"
or is not given,
the listening port will be bound for local use only.
Note that if GatewayPorts
is "no"
on the
remote, "localhost"
is always used as a bind_address.
If rport
is 0
, the TCP port will be allocated on the remote.bind_address
- bind addressrport
- remote porthost
- host addresslport
- local portsf
- socket factoryJSchException
public void setPortForwardingR(int rport, String daemon) throws JSchException
rport
on the remote will be
forwarded to an instance of the class daemon
.
The class specified by daemon
must implement
ForwardedTCPIPDaemon
.rport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"JSchException
setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
public void setPortForwardingR(int rport, String daemon, Object[] arg) throws JSchException
rport
on the remote will be
forwarded to an instance of the class daemon
with
the argument arg
.
The class specified by daemon
must implement ForwardedTCPIPDaemon
.rport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"arg
- arguments for "daemon"JSchException
setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
public void setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg) throws JSchException
bind_address
is an empty string
or "*"
, the port should be available from all interfaces.
If bind_address
is "localhost"
or is not given,
the listening port will be bound for local use only.
Note that if GatewayPorts
is "no"
on the
remote, "localhost"
is always used as a bind_address.
The TCP connection to rport
on the remote will be
forwarded to an instance of the class daemon
with the
argument arg
.
The class specified by daemon
must implement ForwardedTCPIPDaemon
.bind_address
- bind addressrport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"arg
- arguments for "daemon"JSchException
setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
public String[] getPortForwardingR() throws JSchException
JSchException
public int setPortForwardingL(String conf) throws JSchException
bind_address
is an empty string or "*"
,
the port should be available from all interfaces.
If bind_address
is "localhost"
or is not given,
the listening port will be bound for local use only.conf
- configuration of local port forwardingJSchException
setPortForwardingL(String bind_address, int lport, String host, int rport)
public int setPortForwardingR(String conf) throws JSchException
"*"
or an empty string,
then the forwarding is requested to listen on all interfaces.
Note that if GatewayPorts
is "no"
on the remote,
"localhost"
is always used for bind_address.
If the specified remote is "0"
,
the TCP port will be allocated on the remote.conf
- configuration of remote port forwardingJSchException
setPortForwardingR(String bind_address, int rport, String host, int rport)
public Channel getStreamForwarder(String host, int port) throws JSchException
host
:port
.
Set I/O stream to the given channel, and then invoke Channel#connect() method.host
- remote host, which the given stream will be plugged to.port
- remote port, which the given stream will be plugged to.JSchException
public void delPortForwardingR(int rport) throws JSchException
rport
.rport
- remote TCP portJSchException
public void delPortForwardingR(String bind_address, int rport) throws JSchException
rport
bound on the interface at
bind_address
.bind_address
- bind address of the interface on the remoterport
- remote TCP portJSchException
public void setProxy(Proxy proxy)
SocketFactory
or
create plain TCP Socket
s.public void setHost(String host)
JSch.getSession(java.lang.String)
, so there
is no need to call it, if you don't want to change this host.
This should be called before connect()
.public void setPort(int port)
JSch.getSession(java.lang.String)
, so there
is no need to call it, if you don't want to change the port.
This should be called before connect()
.public void setUserInfo(UserInfo userinfo)
public UserInfo getUserInfo()
public void setInputStream(InputStream in)
public void setOutputStream(OutputStream out)
public void setX11Host(String host)
The default value is "127.0.0.1", this is localhost.
Attention: This is effectively a static property, shared by all X11-channels, Sessions and even JSch objects. Forwarding different X11 displays at the same time (from the same Java VM) is not supported.setX11Port(int)
,
setX11Cookie(java.lang.String)
public void setX11Port(int port)
The default value is 6000, the default port for a X11 server on display 0.
Attention: This is effectively a static property, shared by all X11-channels, Sessions and even JSch objects. Forwarding different X11 displays at the same time (from the same Java VM) is not supported.public void setX11Cookie(String cookie)
This implementation assumes the MIT-MAGIC_COOKIE-1 authentication protocol.
Attention: This is effectively a static property, shared by all X11-channels, Sessions and even JSch objects. Forwarding different X11 displays at the same time (from the same Java VM) is not supported.cookie
- the cookie in hexadecimal encoding, should be
string of length 32.setX11Host(java.lang.String)
,
setX11Port(int)
public void setPassword(String password)
password
- the new password. (We will use the UTF-8 encoding
of this string as the actual password sent to the server.)setPassword(byte[])
public void setPassword(byte[] password)
password
, if it is not nullkeyboard-interactive
if it is not null,
the prompt starts with "password:"
and no
UserInfo is given.password
- the new password.public void setConfig(Properties newconf)
newconf
- a properties object, which should contain only
String keys and values. All the current keys/value pairs are
copied to our current configuration.setConfig(String, String)
public void setConfig(Hashtable newconf)
newconf
- a hash table, which should contain only
String keys and values. All the current keys/value pairs are
copied to our current configuration.setConfig(String, String)
public void setConfig(String key, String value)
key
- the configuration keyvalue
- the configuration value.public String getConfig(String key)
JSch.setConfig(java.util.Hashtable)
.key
- the key for the configuration optionpublic void setSocketFactory(SocketFactory sfactory)
public boolean isConnected()
public int getTimeout()
setTimeout(int)
public void setTimeout(int timeout) throws JSchException
timeout
- a nonnegative integer. A value of 0 (the default value)
indicates "no timeout".JSchException
- if the timeout value is invalid or
the existing socket timeout can't be changed.public String getServerVersion()
public String getClientVersion()
public void setClientVersion(String cv)
cv
- the client version string. This will be encoded
in the platform's default encoding. (A version string should
normally only contain ASCII characters.)public void sendIgnore() throws Exception
Exception
public void sendKeepAliveMsg() throws Exception
Exception
public HostKey getHostKey()
connect()
.public String getHost()
public String getUserName()
public int getPort()
public void setHostKeyAlias(String hostKeyAlias)
public String getHostKeyAlias()
setHostKeyAlias(java.lang.String)
public void setServerAliveInterval(int interval) throws JSchException
timeout
value
(and nowhere else). If zero is
specified, no keep-alive message must be sent. The default interval
is zero.interval
- the timeout interval in milliseconds before sending
a server alive message, if no message is received from the server.JSchException
getServerAliveInterval()
public int getServerAliveInterval()
setServerAliveInterval(int)
public void setServerAliveCountMax(int count)
count
- the specified countgetServerAliveCountMax()
public int getServerAliveCountMax()
setServerAliveCountMax(int)
public void setDaemonThread(boolean enable)
connect()
.
The default value is false
.enable
- the new value of the property.
If true, all threads will be deamon threads,
i.e. their running does not avoid a shutdown of the VM.
If false, normal non-deamon threads will be used (and the
VM can only shutdown after disconnect()
(or with
System.exit(int)
).public void setIdentityRepository(IdentityRepository identityRepository)
null
.identityRepository
- getIdentityRepository()
public void setHostKeyRepository(HostKeyRepository hostkeyRepository)
hostkeyRepository
- getHostKeyRepository()
public HostKeyRepository getHostKeyRepository()
null
,
JSch#getHostKeyRepository() will be invoked.JSch.getHostKeyRepository()
This is an inofficial Javadoc created by PaĆlo Ebermann. Have a look at the official homepage.