當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.setPortForwardingL方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:napstr,項目名稱:SqlSauce,代碼行數:33,代碼來源:SshTunnel.java

示例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;
}
 
開發者ID:organicsmarthome,項目名稱:OSHv4,代碼行數:19,代碼來源:SingleSQLAndSSHConnectionProvider.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:JSchChannelsSupport.java

示例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();
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:15,代碼來源:OpenShiftNode.java

示例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;
}
 
開發者ID:cronn-de,項目名稱:ssh-proxy,代碼行數:10,代碼來源:SshProxy.java


注:本文中的com.jcraft.jsch.Session.setPortForwardingL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。