public void open ( ) throws JSchException { if ( isOpen ( ) ) { return ; } session = sessionFactory . newSession ( ) ; logger . debug ( "connecting session" ) ; session . connect ( ) ; for ( Tunnel tunnel : tunnels ) { int assignedPort = 0 ; if ( tunnel . getLocalAlias ( ) == null ) { assignedPort = session . setPortForwardingL ( tunnel . getLocalPort ( ) , tunnel . getDestinationHostname ( ) , tunnel . getDestinationPort ( ) ) ; } else { assignedPort = session . setPortForwardingL ( tunnel . getLocalAlias ( ) , tunnel . getLocalPort ( ) , tunnel . getDestinationHostname ( ) , tunnel . getDestinationPort ( ) ) ; } tunnel . setAssignedLocalPort ( assignedPort ) ; logger . debug ( "added tunnel {}" , tunnel ) ; } logger . info ( "forwarding {}" , this ) ; }
Opens a session and connects all of the tunnels .