当前位置: 首页>>代码示例>>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;未经允许,请勿转载。