Skip to content

Commit 9865d6f

Browse files
committed
add: 供参考的jsch映射端口
1 parent a0d3691 commit 9865d6f

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

nutz-integration-jsch/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

nutz-integration-jsch/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.nutz</groupId>
6+
<artifactId>nutzmore</artifactId>
7+
<version>1.b.52-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>nutz-integration-jsch</artifactId>
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.jcraft</groupId>
13+
<artifactId>jsch</artifactId>
14+
<version>0.1.51</version>
15+
</dependency>
16+
</dependencies>
17+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.nutz.integration.jsch;
2+
3+
import org.nutz.lang.Lang;
4+
import org.nutz.log.Log;
5+
import org.nutz.log.Logs;
6+
7+
import com.jcraft.jsch.JSch;
8+
import com.jcraft.jsch.JSchException;
9+
import com.jcraft.jsch.Session;
10+
11+
/**
12+
* 使用说明, 声明个ioc的bean, 设置属性, 并设置create event调用init方法. <p/> TODO 断线重连之类的
13+
* @author wendal([email protected])
14+
*
15+
*/
16+
public class JschPortMapping {
17+
18+
protected static final Log log = Logs.get().setTag("jsch");
19+
20+
protected String host;
21+
protected int port = 22;
22+
protected int lport = 3306;
23+
protected int rport = 3306;
24+
protected String rhost = "localhost";
25+
protected String user = "root";
26+
protected String password;
27+
JSch jsch;
28+
Session session;
29+
30+
public JschPortMapping() {
31+
jsch = new JSch();
32+
}
33+
34+
public void init() throws JSchException {
35+
session = jsch.getSession(user, host, port);
36+
session.setPassword(password);
37+
session.setConfig("StrictHostKeyChecking", "no");
38+
System.out.println("Establishing Connection...");
39+
session.connect();
40+
int assinged_port= session.setPortForwardingL(lport, rhost, rport);
41+
log.info("local assinged_port="+assinged_port);
42+
}
43+
44+
public void depose() {
45+
if (session != null)
46+
session.disconnect();
47+
}
48+
49+
public static void main(String[] args) throws JSchException {
50+
JschPortMapping m = new JschPortMapping();
51+
m.host = ""; //TODO change yourself
52+
m.user = ""; //TODO change yourself
53+
m.password = ""; //TODO change yourself
54+
55+
m.init();
56+
Lang.quiteSleep(5*60*1000);
57+
}
58+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
<module>nutz-plugins-views</module>
5555
<module>nutz-plugins-xmlentitymaker</module>
5656
<module>nutz-plugins-iocloader</module>
57+
<module>nutz-integration-jsch</module>
5758
</modules>
5859
</project>

0 commit comments

Comments
 (0)