Package com.jcraft.jsch
Class Session
java.lang.Object
com.jcraft.jsch.Session
- All Implemented Interfaces:
Runnable
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
void
connect
(int connectTimeout) void
delPortForwardingL
(int lport) Cancels the local port forwarding assigned at local TCP portlport
on loopback interface.void
delPortForwardingL
(String bind_address, int lport) Cancels the local port forwarding assigned at local TCP portlport
onbind_address
interface.void
delPortForwardingR
(int rport) Cancels the remote port forwarding assigned at remote TCP portrport
.void
delPortForwardingR
(String bind_address, int rport) Cancels the remote port forwarding assigned at remote TCP portrport
bound on the interface atbind_address
.void
void
getHost()
Gets the hostkeyRepository.int
getPort()
String[]
Lists the registered local port forwarding.String[]
Lists the registered remote port forwarding.int
Returns setting for the threshold to send keep-alive messages.int
Returns setting for the interval to send a keep-alive message.getStreamForwarder
(String host, int port) Instantiates an instance of stream-forwarder tohost
:port
.int
boolean
void
openChannel
(String type) void
rekey()
void
run()
void
void
void
void
void
void
setConfig
(Properties newconf) void
setDaemonThread
(boolean enable) void
void
setHostKeyAlias
(String hostKeyAlias) 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
void
void
setPassword
(byte[] password) void
setPassword
(String password) void
setPort
(int port) 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
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 interval to send a keep-alive message.void
setSocketFactory
(SocketFactory sfactory) void
setTimeout
(int timeout) void
setUserInfo
(UserInfo userinfo) void
setX11Cookie
(String cookie) void
setX11Host
(String host) void
setX11Port
(int port) void
-
Field Details
-
daemon_thread
protected boolean daemon_thread
-
-
Method Details
-
connect
- Throws:
JSchException
-
connect
- Throws:
JSchException
-
rekey
- Throws:
Exception
-
openChannel
- Throws:
JSchException
-
encode
- Throws:
Exception
-
read
- Throws:
Exception
-
write
- Throws:
Exception
-
run
public void run() -
disconnect
public void disconnect() -
setPortForwardingL
Registers the local port forwarding for loop-back interface. Iflport
is0
, the tcp port will be allocated.- Parameters:
lport
- local port for local port forwardinghost
- host address for local port forwardingrport
- remote port number for local port forwarding- Returns:
- an allocated local TCP port number
- Throws:
JSchException
- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport) throws JSchException Registers the local port forwarding. Ifbind_address
is an empty string or '*', the port should be available from all interfaces. Ifbind_address
is"localhost"
ornull
, the listening port will be bound for local use only. Iflport
is0
, the tcp port will be allocated.- Parameters:
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 forwarding- Returns:
- an allocated local TCP port number
- Throws:
JSchException
- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf) throws JSchException Registers the local port forwarding. Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
ornull
, the listening port will be bound for local use only. Iflport
is0
, the tcp port will be allocated.- Parameters:
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 factory- Returns:
- an allocated local TCP port number
- Throws:
JSchException
- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) throws JSchException Registers the local port forwarding. Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
ornull
, the listening port will be bound for local use only. Iflport
is0
, the tcp port will be allocated.- Parameters:
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 connection- Returns:
- an allocated local TCP port number
- Throws:
JSchException
-
delPortForwardingL
Cancels the local port forwarding assigned at local TCP portlport
on loopback interface.- Parameters:
lport
- local TCP port- Throws:
JSchException
-
delPortForwardingL
Cancels the local port forwarding assigned at local TCP portlport
onbind_address
interface.- Parameters:
bind_address
- bind_address of network interfaceslport
- local TCP port- Throws:
JSchException
-
getPortForwardingL
Lists the registered local port forwarding.- Returns:
- a list of "lport:host:hostport"
- Throws:
JSchException
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote.- Parameters:
rport
- remote porthost
- host addresslport
- local port- Throws:
JSchException
- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String host, int lport) throws JSchException Registers the remote port forwarding. Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
or is not given, the listening port will be bound for local use only. Note that ifGatewayPorts
is"no"
on the remote,"localhost"
is always used as a bind_address.- Parameters:
bind_address
- bind addressrport
- remote porthost
- host addresslport
- local port- Throws:
JSchException
- See Also:
-
setPortForwardingR
public void setPortForwardingR(int rport, String host, int lport, SocketFactory sf) throws JSchException Registers the remote port forwarding for the loopback interface of the remote.- Parameters:
rport
- remote porthost
- host addresslport
- local portsf
- socket factory- Throws:
JSchException
- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf) throws JSchException Registers the remote port forwarding. Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
or is not given, the listening port will be bound for local use only. Note that ifGatewayPorts
is"no"
on the remote,"localhost"
is always used as a bind_address. Ifrport
is0
, the TCP port will be allocated on the remote.- Parameters:
bind_address
- bind addressrport
- remote porthost
- host addresslport
- local portsf
- socket factory- Throws:
JSchException
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote. The TCP connection torport
on the remote will be forwarded to an instance of the classdaemon
. The class specified bydaemon
must implementForwardedTCPIPDaemon
.- Parameters:
rport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"- Throws:
JSchException
- See Also:
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote. The TCP connection torport
on the remote will be forwarded to an instance of the classdaemon
with the argumentarg
. The class specified bydaemon
must implementForwardedTCPIPDaemon
.- Parameters:
rport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"arg
- arguments for "daemon"- Throws:
JSchException
- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg) throws JSchException Registers the remote port forwarding. Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
or is not given, the listening port will be bound for local use only. Note that ifGatewayPorts
is"no"
on the remote,"localhost"
is always used as a bind_address. The TCP connection torport
on the remote will be forwarded to an instance of the classdaemon
with the argumentarg
. The class specified bydaemon
must implementForwardedTCPIPDaemon
.- Parameters:
bind_address
- bind addressrport
- remote portdaemon
- class name, which implements "ForwardedTCPIPDaemon"arg
- arguments for "daemon"- Throws:
JSchException
- See Also:
-
getPortForwardingR
Lists the registered remote port forwarding.- Returns:
- a list of "rport:host:hostport"
- Throws:
JSchException
-
setPortForwardingL
Registers the local port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". Ifbind_address
is an empty string or"*"
, the port should be available from all interfaces. Ifbind_address
is"localhost"
or is not given, the listening port will be bound for local use only.- Parameters:
conf
- configuration of local port forwarding- Returns:
- an assigned port number
- Throws:
JSchException
- See Also:
-
setPortForwardingR
Registers the remote port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". If the bind_address is not given, the default is to only bind to loopback addresses. If the bind_address is"*"
or an empty string, then the forwarding is requested to listen on all interfaces. Note that ifGatewayPorts
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.- Parameters:
conf
- configuration of remote port forwarding- Returns:
- an allocated TCP port on the remote.
- Throws:
JSchException
- See Also:
-
getStreamForwarder
Instantiates an instance of stream-forwarder tohost
:port
. Set I/O stream to the given channel, and then invoke Channel#connect() method.- Parameters:
host
- remote host, which the given stream will be plugged to.port
- remote port, which the given stream will be plugged to.- Throws:
JSchException
-
delPortForwardingR
Cancels the remote port forwarding assigned at remote TCP portrport
.- Parameters:
rport
- remote TCP port- Throws:
JSchException
-
delPortForwardingR
Cancels the remote port forwarding assigned at remote TCP portrport
bound on the interface atbind_address
.- Parameters:
bind_address
- bind address of the interface on the remoterport
- remote TCP port- Throws:
JSchException
-
setProxy
-
setHost
-
setPort
public void setPort(int port) -
setUserInfo
-
getUserInfo
-
setInputStream
-
setOutputStream
-
setX11Host
-
setX11Port
public void setX11Port(int port) -
setX11Cookie
-
setPassword
-
setPassword
public void setPassword(byte[] password) -
setConfig
-
setConfig
-
setConfig
-
getConfig
-
setSocketFactory
-
isConnected
public boolean isConnected() -
getTimeout
public int getTimeout() -
setTimeout
- Throws:
JSchException
-
getServerVersion
-
getClientVersion
-
setClientVersion
-
sendIgnore
- Throws:
Exception
-
sendKeepAliveMsg
- Throws:
Exception
-
noMoreSessionChannels
- Throws:
Exception
-
getHostKey
-
getHost
-
getUserName
-
getPort
public int getPort() -
setHostKeyAlias
-
getHostKeyAlias
-
setServerAliveInterval
Sets the interval to send a keep-alive message. If zero is specified, any keep-alive message must not be sent. The default interval is zero.- Parameters:
interval
- the specified interval, in milliseconds.- Throws:
JSchException
- See Also:
-
getServerAliveInterval
public int getServerAliveInterval()Returns setting for the interval to send a keep-alive message.- See Also:
-
setServerAliveCountMax
public void setServerAliveCountMax(int count) Sets the number of keep-alive messages which may be sent without receiving any messages back from the server. If this threshold is reached while keep-alive messages are being sent, the connection will be disconnected. The default value is one.- Parameters:
count
- the specified count- See Also:
-
getServerAliveCountMax
public int getServerAliveCountMax()Returns setting for the threshold to send keep-alive messages.- See Also:
-
setDaemonThread
public void setDaemonThread(boolean enable) -
setIdentityRepository
Sets the identityRepository, which will be referred in the public key authentication. The default value isnull
.- Parameters:
identityRepository
-- See Also:
-
setHostKeyRepository
Sets the hostkeyRepository, which will be referred in checking host keys.- Parameters:
hostkeyRepository
-- See Also:
-
getHostKeyRepository
Gets the hostkeyRepository. If this.hostkeyRepository isnull
, JSch#getHostKeyRepository() will be invoked.- See Also:
-