/** * 解除端口映射 * * @param session 需要解除端口映射的SSH会话 * @param localPort 需要解除的本地端口 * @return 解除成功与否 */ public static boolean unBindPort(Session session, int localPort) { try { session.delPortForwardingL(localPort); return true; } catch (JSchException e) { throw new JschRuntimeException(e); } }
/** * 解除端口映射 * * @param session 需要解除端口映射的SSH会话 * @param localPort 需要解除的本地端口 * @return 解除成功与否 */ public static boolean unBindPort(Session session, int localPort) { try { session.delPortForwardingL(localPort); return true; } catch (JSchException e) { throw new JschRuntimeException(e); } }
/** * Cancels the local port forwarding assigned * at local TCP port <code>lport</code> on loopback interface. * * @param lport local TCP port */ public void delPortForwardingL(int lport) throws JSchException { delPortForwardingL("127.0.0.1", lport); }
/** * Cancels the local port forwarding assigned * at local TCP port <code>lport</code> on loopback interface. * * @param lport local TCP port */ public void delPortForwardingL(int lport) throws JSchException{ delPortForwardingL("127.0.0.1", lport); }
/** * Cancels the local port forwarding assigned * at local TCP port <code>lport</code> on loopback interface. * * @param lport local TCP port */ public void delPortForwardingL(int lport) throws JSchException{ delPortForwardingL("127.0.0.1", lport); }
/** * Cancels the local port forwarding assigned * at local TCP port <code>lport</code> on loopback interface. * * @param lport local TCP port */ public void delPortForwardingL(int lport) throws JSchException{ delPortForwardingL("127.0.0.1", lport); }
public void delPortForwardingL(int lport) throws JSchException{ delPortForwardingL("127.0.0.1", lport); } public void delPortForwardingL(String boundaddress, int lport) throws JSchException{
protected void onClose() throws SshException { try { session.delPortForwardingL(localAddress, localPort); } catch (JSchException e) { throw new SshException("Failed to configure local port forward"); } finally { channelCount--; } } };
/** * 解除端口映射 * * @param session 需要解除端口映射的SSH会话 * @param localPort 需要解除的本地端口 * @return 解除成功与否 */ public static boolean unBindPort(Session session, int localPort) { try { session.delPortForwardingL(localPort); return true; } catch (JSchException e) { throw new JschRuntimeException(e); } }
/** * 解除端口映射 * @param session 需要解除端口映射的SSH会话 * @param localPort 需要解除的本地端口 * @return 解除成功与否 */ synchronized public static boolean unBindPort(Session session, int localPort){ try { session.delPortForwardingL(localPort); return true; } catch (JSchException e) { logger.error("端口映射解除失败,原因是:" + e.getMessage()); } return false; }
public void stop(final Session session) throws OpenShiftSSHOperationException { if (isStarted(session)) { try { session.delPortForwardingL(localAddress, localPort); } catch (Exception e) { throw new OpenShiftSSHOperationException(e, "Failed to stop port forwarding on {0}:{1}", this.localAddress, this.localPort); } } }
public void stop(final Session session) throws OpenShiftSSHOperationException { if (isStarted(session)) { try { session.delPortForwardingL(localAddress, localPort); } catch (Exception e) { throw new OpenShiftSSHOperationException(e, "Failed to stop port forwarding on {0}:{1}", this.localAddress, this.localPort); } } }
@Test public void testLocalForwarding() throws Exception { Session session = createSession(); try { int forwardedPort = Utils.getFreePort(); session.setPortForwardingL(forwardedPort, TEST_LOCALHOST, echoPort); try (Socket s = new Socket(TEST_LOCALHOST, forwardedPort); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.delPortForwardingL(forwardedPort); } } finally { session.disconnect(); } }
@Test public void testLocalForwarding() throws Exception { Session session = createSession(); try { int forwardedPort = Utils.getFreePort(); session.setPortForwardingL(forwardedPort, TEST_LOCALHOST, echoPort); try (Socket s = new Socket(TEST_LOCALHOST, forwardedPort); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.delPortForwardingL(forwardedPort); } } finally { session.disconnect(); } }
@Test public void testLocalForwarding() throws Exception { Session session = createSession(); try { int forwardedPort = Utils.getFreePort(); session.setPortForwardingL(forwardedPort, TEST_LOCALHOST, echoPort); try (Socket s = new Socket(TEST_LOCALHOST, forwardedPort); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream()) { s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L)); String expected = getCurrentTestName(); byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); output.write(bytes); output.flush(); byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); String res = new String(buf, 0, n); assertEquals("Mismatched data", expected, res); } finally { session.delPortForwardingL(forwardedPort); } } finally { session.disconnect(); } }