- All Superinterfaces:
AutoCloseable,Closeable,org.miaixz.bus.core.Provider,Serializable,org.miaixz.bus.core.lang.Wrapper<Object>
- All Known Implementing Classes:
JschSession,SshjSession
Abstract interface for an SSH (Secure Shell) session. This interface defines common operations for managing an SSH
connection, including checking the connection status and handling port forwarding (tunnelling). It extends
Wrapper to provide access to the underlying session object and Closeable for resource management.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidbindLocalPort(int localPort, InetSocketAddress remoteAddress) Binds a local port to a remote address, creating a local port forwarding tunnel.voidbindLocalPort(InetSocketAddress localAddress, InetSocketAddress remoteAddress) Binds a local address (host and port) to a remote address, creating a local port forwarding tunnel.voidbindRemotePort(InetSocketAddress remoteAddress, InetSocketAddress localAddress) Binds a port on the remote SSH server to a local address, creating a remote port forwarding tunnel.booleanChecks if the SSH session is currently connected and active.default voidunBindLocalPort(int localPort) Removes a local port forwarding binding.voidunBindLocalPort(InetSocketAddress localAddress) Removes a local port forwarding binding for a specific local address.voidunBindRemotePort(InetSocketAddress remoteAddress) Removes a remote port forwarding binding.Methods inherited from interface org.miaixz.bus.core.lang.Wrapper
getRaw, type
-
Method Details
-
isConnected
boolean isConnected()Checks if the SSH session is currently connected and active.- Returns:
trueif the session is connected,falseotherwise.
-
bindLocalPort
Binds a local port to a remote address, creating a local port forwarding tunnel. This is useful for accessing a service on a remote network that is only accessible from the SSH server. For example, a request tolocalhost:localPorton the client machine will be forwarded through the SSH tunnel toremoteHost:remotePorton the server's network.- Parameters:
localPort- The local port on the client machine to listen on.remoteAddress- TheInetSocketAddressof the remote host and port to forward traffic to.
-
bindLocalPort
Binds a local address (host and port) to a remote address, creating a local port forwarding tunnel. This is an extended version ofbindLocalPort(int, InetSocketAddress)that allows specifying the local bind address.- Parameters:
localAddress- The localInetSocketAddresson the client machine to bind to.remoteAddress- The remoteInetSocketAddressto forward traffic to.
-
unBindLocalPort
default void unBindLocalPort(int localPort) Removes a local port forwarding binding.- Parameters:
localPort- The local port that was previously bound.- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if an error occurs while unbinding the port.
-
unBindLocalPort
Removes a local port forwarding binding for a specific local address.- Parameters:
localAddress- The localInetSocketAddressthat was previously bound.
-
bindRemotePort
Binds a port on the remote SSH server to a local address, creating a remote port forwarding tunnel. This is useful for allowing the remote server to access a service running on the local client machine. For example, a connection toremoteAddresson the SSH server will be forwarded through the tunnel tolocalAddresson the client machine.- Parameters:
remoteAddress- TheInetSocketAddresson the SSH server to bind.localAddress- The localInetSocketAddressto forward traffic to.- Throws:
org.miaixz.bus.core.lang.exception.InternalException- if an error occurs while binding the remote port.
-
unBindRemotePort
Removes a remote port forwarding binding.- Parameters:
remoteAddress- The remoteInetSocketAddressthat was previously bound.
-