本文整理匯總了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;
}