mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
25e10f04d1
commit
6bf77fd36a
@ -13,6 +13,7 @@
|
||||
* 【poi 】 增加CellSetter,可以自定义单元格值写出
|
||||
* 【poi 】 CsvReader增加readFromStr(pr#1755@Github)
|
||||
* 【socket 】 SocketUtil增加connection方法
|
||||
* 【extra 】 JschUtil增加bindPort重载方法(issue#I44UTH@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 改进NumberChineseFormatter算法,补充完整单元测试,解决零问题
|
||||
|
@ -133,7 +133,7 @@ public class JschUtil {
|
||||
* @return SSH会话
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static Session createSession(String sshHost, int sshPort, String sshUser, String sshPass) {
|
||||
public static Session createSession(String sshHost, int sshPort, String sshUser, String sshPass) {
|
||||
final JSch jsch = new JSch();
|
||||
final Session session = createSession(jsch, sshHost, sshPort, sshUser);
|
||||
|
||||
@ -215,17 +215,34 @@ public class JschUtil {
|
||||
* @throws JschRuntimeException 端口绑定失败异常
|
||||
*/
|
||||
public static boolean bindPort(Session session, String remoteHost, int remotePort, int localPort) throws JschRuntimeException {
|
||||
return bindPort(session, remoteHost, remotePort, "127.0.0.1", localPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定端口到本地。 一个会话可绑定多个端口
|
||||
*
|
||||
* @param session 需要绑定端口的SSH会话
|
||||
* @param remoteHost 远程主机
|
||||
* @param remotePort 远程端口
|
||||
* @param localHost 本地主机
|
||||
* @param localPort 本地端口
|
||||
* @return 成功与否
|
||||
* @throws JschRuntimeException 端口绑定失败异常
|
||||
* @since 5.7.8
|
||||
*/
|
||||
public static boolean bindPort(Session session, String remoteHost, int remotePort, String localHost, int localPort) throws JschRuntimeException {
|
||||
if (session != null && session.isConnected()) {
|
||||
try {
|
||||
session.setPortForwardingL(localPort, remoteHost, remotePort);
|
||||
session.setPortForwardingL(localHost, localPort, remoteHost, remotePort);
|
||||
} catch (JSchException e) {
|
||||
throw new JschRuntimeException(e, "From [{}] mapping to [{}] error!", remoteHost, localPort);
|
||||
throw new JschRuntimeException(e, "From [{}:{}] mapping to [{}:{}] error!", remoteHost, remotePort, localHost, localPort);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定ssh服务端的serverPort端口, 到host主机的port端口上. <br>
|
||||
* 即数据从ssh服务端的serverPort端口, 流经ssh客户端, 达到host:port上.
|
||||
|
Loading…
x
Reference in New Issue
Block a user