private void authenticate() { try { if (connection.authenticateWithNone(profile.getUser())) { Log.d(TAG, "Authenticate with none"); return; } } catch (Exception e) { Log.d(TAG, "Host does not support 'none' authentication."); } try { if (connection.isAuthMethodAvailable(profile.getUser(), AUTH_PUBLICKEY)) { File f = new File(profile.getKeyPath()); if (f.exists()) if (profile.getPassword().equals("")) profile.setPassword(null); if (connection.authenticateWithPublicKey(profile.getUser(), f, profile.getPassword())) { Log.d(TAG, "Authenticate with public key"); return; } } } catch (Exception e) { Log.d(TAG, "Host does not support 'Public key' authentication."); } try { if (connection.isAuthMethodAvailable(profile.getUser(), AUTH_PASSWORD)) { if (connection.authenticateWithPassword(profile.getUser(), profile.getPassword())) { Log.d(TAG, "Authenticate with password"); return; } } } catch (IllegalStateException e) { Log.e(TAG, "Connection went away while we were trying to authenticate", e); } catch (Exception e) { Log.e(TAG, "Problem during handleAuthentication()", e); } // TODO: Need verification try { if (connection.isAuthMethodAvailable(profile.getUser(), AUTH_KEYBOARDINTERACTIVE)) { if (connection.authenticateWithKeyboardInteractive(profile.getUser(), this)) return; } } catch (Exception e) { Log.d(TAG, "Host does not support 'Keyboard-Interactive' authentication."); } }