@ Override public synchronized void connect ( ) throws IOException { logger . debug ( "connecting..." ) ; Authentication auth = authentication ; if ( updater != null ) { Authentication updatedAuth = updater . updateAuthentication ( authentication ) ; if ( updatedAuth != null && auth != updatedAuth ) { auth = updatedAuth ; } } try { client = new JSch ( ) ; if ( auth . getPrivateKeyPhrase ( ) == null ) { client . addIdentity ( auth . getPrivateKeyFile ( ) . getAbsolutePath ( ) , auth . getPrivateKeyFilePassword ( ) ) ; } else { client . addIdentity ( auth . getUsername ( ) , auth . getPrivateKeyPhrase ( ) , null , auth . getPrivateKeyFilePassword ( ) . getBytes ( "UTF-8" ) ) ; } client . setHostKeyRepository ( new BlindHostKeyRepository ( ) ) ; connectSession = client . getSession ( auth . getUsername ( ) , host , port ) ; connectSession . setConfig ( "PreferredAuthentications" , "publickey" ) ; if ( proxy != null && ! proxy . isEmpty ( ) ) { String [ ] splitted = proxy . split ( ":" ) ; if ( splitted . length > 2 && splitted [ 1 ] . length ( ) >= PROTO_HOST_DELIM_LENGTH ) { String pproto = splitted [ 0 ] ; String phost = splitted [ 1 ] . substring ( 2 ) ; int pport = Integer . parseInt ( splitted [ 2 ] ) ; if ( pproto . equals ( "socks5" ) || pproto . equals ( "http" ) ) { if ( pproto . equals ( "socks5" ) ) { connectSession . setProxy ( new ProxySOCKS5 ( phost , pport ) ) ; } else { connectSession . setProxy ( new ProxyHTTP ( phost , pport ) ) ; } } else { throw new MalformedURLException ( "Only http and socks5 protocols are supported" ) ; } } else { throw new MalformedURLException ( proxy ) ; } } connectSession . connect ( this . connectionTimeout ) ; logger . debug ( "Connected: {}" , connectSession . isConnected ( ) ) ; connectSession . setServerAliveInterval ( ALIVE_INTERVAL ) ; } catch ( JSchException ex ) { throw new SshException ( ex ) ; } }
Connects the connection .