()
| 93 | .execute( |
| 94 | new Runnable() { |
| 95 | public void run() { |
| 96 | try { |
| 97 | String host = args.optString(0); |
| 98 | int port = args.optInt(1); |
| 99 | String username = args.optString(2); |
| 100 | String password = args.optString(3); |
| 101 | JCEProvider.enableBouncyCastle(true); |
| 102 | Log.d( |
| 103 | TAG, |
| 104 | "Connecting to " + host + ":" + port + " as " + username |
| 105 | ); |
| 106 | ssh = SshClientBuilder.create() |
| 107 | .withHostname(host) |
| 108 | .withPort(port) |
| 109 | .withUsername(username) |
| 110 | .withPassword(password) |
| 111 | .build(); |
| 112 | |
| 113 | if (ssh.isConnected()) { |
| 114 | connectionID = username + "@" + host; |
| 115 | |
| 116 | try { |
| 117 | sftp = SftpClientBuilder.create().withClient(ssh).build(); |
| 118 | } catch (IOException | SshException e) { |
| 119 | ssh.close(); |
| 120 | callback.error( |
| 121 | "Failed to initialize SFTP subsystem: " + errMessage(e) |
| 122 | ); |
| 123 | Log.e(TAG, "Failed to initialize SFTP subsystem", e); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | try { |
| 128 | sftp.getSubsystemChannel().setCharsetEncoding("UTF-8"); |
| 129 | } catch (UnsupportedEncodingException | SshException e) { |
| 130 | // Fallback to default encoding if UTF-8 fails |
| 131 | Log.w( |
| 132 | TAG, |
| 133 | "Failed to set UTF-8 encoding, falling back to default", |
| 134 | e |
| 135 | ); |
| 136 | } |
| 137 | callback.success(); |
| 138 | Log.d(TAG, "Connected successfully to " + connectionID); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | callback.error("Failed to establish SSH connection"); |
| 143 | } catch (UnresolvedAddressException e) { |
| 144 | callback.error("Cannot resolve host address"); |
| 145 | Log.e(TAG, "Cannot resolve host address", e); |
| 146 | } catch (PermissionDeniedException e) { |
| 147 | callback.error("Authentication failed: " + e.getMessage()); |
| 148 | Log.e(TAG, "Authentication failed", e); |
| 149 | } catch (SshException e) { |
| 150 | callback.error("SSH error: " + errMessage(e)); |
| 151 | Log.e(TAG, "SSH error", e); |
| 152 | } catch (IOException e) { |
nothing calls this directly
no test coverage detected