/** * 绑定端口到本地。 一个会话可绑定多个端口 * * @param session 需要绑定端口的SSH会话 * @param remoteHost 远程主机 * @param remotePort 远程端口 * @param localPort 本地端口 * @return 成功与否 * @throws JschRuntimeException 端口绑定失败异常 */ public static boolean bindPort(Session session, String remoteHost, int remotePort, int localPort) throws JschRuntimeException { if (session != null && session.isConnected()) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new JschRuntimeException(e, "From [{}] mapping to [{}] error!", remoteHost, localPort); } return true; } return false; }
/** * 绑定端口到本地。 一个会话可绑定多个端口 * * @param session 需要绑定端口的SSH会话 * @param remoteHost 远程主机 * @param remotePort 远程端口 * @param localPort 本地端口 * @return 成功与否 * @throws JschRuntimeException 端口绑定失败异常 */ public static boolean bindPort(Session session, String remoteHost, int remotePort, int localPort) throws JschRuntimeException { if (session != null && session.isConnected()) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new JschRuntimeException(e, "From [{}] mapping to [{}] error!", remoteHost, localPort); } return true; } return false; }
session.setPortForwardingL(localPort, remoteMongoHost, remoteMongoPort);
/** * Registers the local port forwarding for loop-back interface. * If <code>lport</code> is <code>0</code>, the tcp port will be allocated. * @param lport local port for local port forwarding * @param host host address for local port forwarding * @param rport remote port number for local port forwarding * @return an allocated local TCP port number * @see #setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) */ public int setPortForwardingL(int lport, String host, int rport) throws JSchException{ return setPortForwardingL("127.0.0.1", lport, host, rport); }
/** * Registers the local port forwarding for loop-back interface. * If <code>lport</code> is <code>0</code>, the tcp port will be allocated. * @param lport local port for local port forwarding * @param host host address for local port forwarding * @param rport remote port number for local port forwarding * @return an allocated local TCP port number * @see #setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) */ public int setPortForwardingL(int lport, String host, int rport) throws JSchException{ return setPortForwardingL("127.0.0.1", lport, host, rport); }
/** * Registers the local port forwarding for loop-back interface. * If <code>lport</code> is <code>0</code>, the tcp port will be allocated. * @param lport local port for local port forwarding * @param host host address for local port forwarding * @param rport remote port number for local port forwarding * @return an allocated local TCP port number * @see #setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) */ public int setPortForwardingL(int lport, String host, int rport) throws JSchException{ return setPortForwardingL("127.0.0.1", lport, host, rport); }
public int setPortForwardingL(int lport, String host, int rport) throws JSchException{ return setPortForwardingL("127.0.0.1", lport, host, rport); } public int setPortForwardingL(String boundaddress, int lport, String host, int rport) throws JSchException{
/** * Registers the local port forwarding for loop-back interface. * If <code>lport</code> is <code>0</code>, the tcp port will be allocated. * * @param lport local port for local port forwarding * @param host host address for local port forwarding * @param rport remote port number for local port forwarding * @return an allocated local TCP port number * @see #setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) */ public int setPortForwardingL(int lport, String host, int rport) throws JSchException { return setPortForwardingL("127.0.0.1", lport, host, rport); }
public int setPortForwardingL(String boundaddress, int lport, String host, int rport) throws JSchException{ return setPortForwardingL(boundaddress, lport, host, rport, null); } public int setPortForwardingL(String boundaddress, int lport, String host, int rport, ServerSocketFactory ssf) throws JSchException{
/** * Registers the local port forwarding. If <code>bind_address</code> is an empty string * or '*', the port should be available from all interfaces. * If <code>bind_address</code> is <code>"localhost"</code> or * <code>null</code>, the listening port will be bound for local use only. * If <code>lport</code> is <code>0</code>, the tcp port will be allocated. * @param bind_address bind address for local port forwarding * @param lport local port for local port forwarding * @param host host address for local port forwarding * @param rport remote port number for local port forwarding * @return an allocated local TCP port number * @see #setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) */ public int setPortForwardingL(String bind_address, int lport, String host, int rport) throws JSchException{ return setPortForwardingL(bind_address, lport, host, rport, null); }
@Override public void createLocalTunnel(int localPort, String remoteHost, int remotePort) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new RuntimeException(e); } }
@Override public void createLocalTunnel(int localPort, String remoteHost, int remotePort) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new RuntimeException(e); } }
@Override public void createLocalTunnel(int localPort, String remoteHost, int remotePort) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new RuntimeException(e); } }
@Override public void createLocalTunnel(int localPort, String remoteHost, int remotePort) { try { session.setPortForwardingL(localPort, remoteHost, remotePort); } catch (JSchException e) { throw new RuntimeException(e); } }
JSch jsch = new JSch(); Session session = jsch.getSession(user, host); session.setPassword(password); session.connect(timeout); session.setPortForwardingL(listenPort, destHost, destPort);
protected void onOpen() throws SshException { try { session.setPortForwardingL(localAddress, localPort, remoteHost, remotePort); channelCount++; } catch (JSchException e) { throw new SshException("Failed to configure local port forward"); } }
public static Session forwardLocalPort(String hostname, int port, String username, File keyFile, final String passphrase, int localPortToForward, String remoteHostToForwardTo, int remotePortToForwardTo) throws JSchException, IOException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.setPortForwardingL(localPortToForward, remoteHostToForwardTo, remotePortToForwardTo); session.connect(); return session; }
public static Session forwardLocalPort(String hostname, int port, String username, File keyFile, final String passphrase, int localPortToForward, String remoteHostToForwardTo, int remotePortToForwardTo) throws JSchException, IOException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.setPortForwardingL(localPortToForward, remoteHostToForwardTo, remotePortToForwardTo); session.connect(); return session; }
JSch jsch = new JSch(); Session session = jsch.getSession(user, host); session.setPassword(password); session.connect(timeout); session.setPortForwardingL(listenPort, destHost, destPort);
private Session startSession() { try { Session session = openSession(); session.setTimeout((int) maxwait); session.setPortForwardingL(Integer.parseInt(lport), rhost, Integer.parseInt(rport)); log("SSHTunnel : Connection created successfully.", Project.MSG_INFO); return session; } catch (Exception e) { log("SSHTunnel : Connect Failed", Project.MSG_ERR); throw new BuildException("SSHTunnel Task Failed: Unable to create tunnel", e); } }