public void cancelRemoteForwarding ( String bindAddress , int bindPort , boolean killActiveTunnels ) throws SshException { String key = generateKey ( bindAddress , bindPort ) ; boolean killedTunnels = false ; if ( killActiveTunnels ) { try { ActiveTunnel [ ] tunnels = getRemoteForwardingTunnels ( bindAddress , bindPort ) ; if ( tunnels != null ) { for ( int i = 0 ; i < tunnels . length ; i ++ ) { killedTunnels = true ; tunnels [ i ] . stop ( ) ; } } } catch ( IOException ex ) { } incomingtunnels . remove ( key ) ; } if ( ! remoteforwardings . containsKey ( key ) ) { if ( killActiveTunnels && killedTunnels ) { return ; } throw new SshException ( "Remote forwarding has not been started on " + key , SshException . FORWARDING_ERROR ) ; } // Check to see whether this is local or remote if ( ssh == null ) return ; ssh . cancelRemoteForwarding ( bindAddress , bindPort ) ; String destination = ( String ) remoteforwardings . get ( key ) ; int idx = destination . indexOf ( ":" ) ; String hostToConnect ; int portToConnect ; if ( idx == - 1 ) { throw new SshException ( "Invalid port reference in remote forwarding key!" , SshException . INTERNAL_ERROR ) ; } hostToConnect = destination . substring ( 0 , idx ) ; portToConnect = Integer . parseInt ( destination . substring ( idx + 1 ) ) ; for ( int i = 0 ; i < clientlisteners . size ( ) ; i ++ ) { if ( clientlisteners . elementAt ( i ) != null ) { ( ( ForwardingClientListener ) clientlisteners . elementAt ( i ) ) . forwardingStopped ( ForwardingClientListener . REMOTE_FORWARDING , key , hostToConnect , portToConnect ) ; } } remoteforwardings . remove ( key ) ; }
Requests that the remote side stop listening for socket connections . Please note that this feature is not available on SSH1 connections . The only way to stop the server from listening is to disconnect the connection .