MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / run

Method run

src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java:95–159  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 15

errMessageMethod · 0.95
sanitizePathMethod · 0.95
successMethod · 0.80
getUriMethod · 0.80
getPrivateKeyMethod · 0.80
putMethod · 0.80
getInputStreamMethod · 0.80
isDirectoryMethod · 0.80
mkdirMethod · 0.80
rmMethod · 0.80
createMethod · 0.65
isConnectedMethod · 0.65

Tested by

no test coverage detected