本文整理汇总了Java中com.jcraft.jsch.Session.setPortForwardingL方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setPortForwardingL方法的具体用法?Java Session.setPortForwardingL怎么用?Java Session.setPortForwardingL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.Session
的用法示例。
在下文中一共展示了Session.setPortForwardingL方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureSession
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session configureSession() {
try {
//configure the tunnel
log.info("Configuring SSH tunnel");
Session session = jsch.getSession(
sshDetails.user,
sshDetails.host,
sshDetails.sshPort
);
jsch.addIdentity(sshDetails.keyFile.getPath(), sshDetails.passphrase);
final Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
config.put("ConnectionAttempts", "3");
//dont set the keep alive too low or you might suffer from a breaking connection during start up (for whatever reason)
session.setServerAliveInterval(1000);//milliseconds
session.setConfig(config);
//forward the port
final int assignedPort = session.setPortForwardingL(
sshDetails.localPort,
"localhost",
sshDetails.remotePort
);
log.info("Setting up port forwarding: localhost:" + assignedPort + " -> " + sshDetails.host + ":" + sshDetails.remotePort);
return session;
} catch (final JSchException e) {
throw new RuntimeException("Failed to configure SSH tunnel", e);
}
}
示例2: doSshTunnel
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session doSshTunnel(int nLocalPort) throws JSchException {
final JSch jsch = new JSch();
Session session = jsch.getSession(strSshUser, strSshHost, nSshPort);
if (!useKeyFile)
session.setPassword(strSshPassword);
else
jsch.addIdentity(new File(keyFilePath).getAbsolutePath());
final Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
session.setPortForwardingL(nLocalPort, databaseServerName, databaseServerPort);
return session;
}
示例3: setPortForwardingL
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public int setPortForwardingL(int lport, String host, int rport) throws JSchException {
portForwarding.addPortForwardingInfoL(lport, host, rport);
for (Session s : sessions.keySet()) {
if (s.isConnected()) {
return s.setPortForwardingL(lport, host, rport);
}
}
return -1;
}
示例4: portForward
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public void portForward(final String targetHost, final int targetPort, final Consumer<Integer> code) {
Session ssh = SshUtil.getInstance().createSshSession(username, hostname);
try {
final int localPort = ssh.setPortForwardingL(0, targetHost, targetPort);
ssh.connect();
code.accept(localPort);
LOGGER.debug("Doing port forward {}->{}", localPort, targetPort);
} catch (JSchException x) {
LOGGER.error("Error SSH to " + username + "@" + hostname, x);
throw new IllegalStateException(x);
} finally {
ssh.disconnect();
}
}
示例5: addLocalPortForwarding
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private int addLocalPortForwarding(String sshTunnelHost, Session session, String targetHost, int targetPort, int localPort) throws JSchException {
int localPortReturned = session.setPortForwardingL(localPort, targetHost, targetPort);
log.debug("[{}] local port {} forwarded to {}:{}", sshTunnelHost, localPortReturned, targetHost, targetPort);
Set<Integer> ports = portForwardings.computeIfAbsent(session, k -> new LinkedHashSet<>());
ports.add(Integer.valueOf(localPortReturned));
return localPortReturned;
}