Class MinaSession
java.lang.Object
org.miaixz.bus.extra.ssh.provider.mina.MinaSession
- All Implemented Interfaces:
Closeable,AutoCloseable,org.miaixz.bus.core.lang.Wrapper<Object>,Session
Apache MINA SSHD(https://mina.apache.org/sshd-project/)会话封装
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbindLocalPort(InetSocketAddress localAddress, InetSocketAddress remoteAddress) 绑定端口到本地。 一个会话可绑定多个端口 当请求localHost:localPort时,通过SSH到服务器,转发请求到remoteHost:remotePort 此方法用于访问本地无法访问但是服务器可以访问的地址,如只有服务器能访问的内网数据库等voidbindRemotePort(InetSocketAddress remoteAddress, InetSocketAddress localAddress) 绑定ssh服务端的serverPort端口, 到本地主机的port端口上.voidclose()执行Shell命令exec(String cmd, Charset charset, OutputStream errStream) 执行Shell命令(使用EXEC方式)execByShell(String cmd, Charset charset, OutputStream errStream) 执行Shell命令getRaw()boolean是否连接状态voidunBindLocalPort(InetSocketAddress localAddress) 解除本地端口映射voidunBindRemotePort(InetSocketAddress remoteAddress) 解除远程端口映射Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.extra.ssh.Session
bindLocalPort, unBindLocalPort
-
Constructor Details
-
MinaSession
构造- Parameters:
connector- 连接信息
-
-
Method Details
-
getRaw
- Specified by:
getRawin interfaceorg.miaixz.bus.core.lang.Wrapper<Object>
-
isConnected
public boolean isConnected()Description copied from interface:Session是否连接状态- Specified by:
isConnectedin interfaceSession- Returns:
- 是否连接状态
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
bindLocalPort
public void bindLocalPort(InetSocketAddress localAddress, InetSocketAddress remoteAddress) throws org.miaixz.bus.core.lang.exception.InternalException Description copied from interface:Session绑定端口到本地。 一个会话可绑定多个端口 当请求localHost:localPort时,通过SSH到服务器,转发请求到remoteHost:remotePort 此方法用于访问本地无法访问但是服务器可以访问的地址,如只有服务器能访问的内网数据库等- Specified by:
bindLocalPortin interfaceSession- Parameters:
localAddress- 本地主机和端口remoteAddress- 远程主机和端口- Throws:
org.miaixz.bus.core.lang.exception.InternalException
-
unBindLocalPort
public void unBindLocalPort(InetSocketAddress localAddress) throws org.miaixz.bus.core.lang.exception.InternalException Description copied from interface:Session解除本地端口映射- Specified by:
unBindLocalPortin interfaceSession- Parameters:
localAddress- 需要解除的本地地址- Throws:
org.miaixz.bus.core.lang.exception.InternalException
-
bindRemotePort
public void bindRemotePort(InetSocketAddress remoteAddress, InetSocketAddress localAddress) throws org.miaixz.bus.core.lang.exception.InternalException Description copied from interface:Session绑定ssh服务端的serverPort端口, 到本地主机的port端口上. 即数据从ssh服务端的serverPort端口, 流经ssh客户端, 达到host:port上. 此方法用于在服务端访问本地资源,如服务器访问本机所在的数据库等。- Specified by:
bindRemotePortin interfaceSession- Parameters:
remoteAddress- ssh服务端上要被绑定的地址localAddress- 转发到的本地地址- Throws:
org.miaixz.bus.core.lang.exception.InternalException- 端口绑定失败异常
-
unBindRemotePort
public void unBindRemotePort(InetSocketAddress remoteAddress) throws org.miaixz.bus.core.lang.exception.InternalException Description copied from interface:Session解除远程端口映射- Specified by:
unBindRemotePortin interfaceSession- Parameters:
remoteAddress- 需要解除的远程地址和端口- Throws:
org.miaixz.bus.core.lang.exception.InternalException
-
exec
执行Shell命令- Parameters:
cmd- 命令charset- 发送和读取内容的编码- Returns:
- 结果
-
exec
执行Shell命令(使用EXEC方式)此方法单次发送一个命令到服务端,不读取环境变量,执行结束后自动关闭channel,不会产生阻塞。
参考:https://github.com/apache/mina-sshd/blob/master/docs/client-setup.md#running-a-command-or-opening-a-shell- Parameters:
cmd- 命令charset- 发送和读取内容的编码errStream- 错误信息输出到的位置- Returns:
- 执行结果内容
-
execByShell
执行Shell命令此方法单次发送一个命令到服务端,自动读取环境变量,执行结束后自动关闭channel,不会产生阻塞。
- Parameters:
cmd- 命令charset- 发送和读取内容的编码errStream- 异常输出位置- Returns:
- 结果
-