Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 86 additions & 24 deletions src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

public class Sftp extends CordovaPlugin {

private static final String TAG = "SFTP";
private SshClient ssh;
private SftpClient sftp;
private Context context;
Expand Down Expand Up @@ -93,6 +94,10 @@ public void run() {
int port = args.optInt(1);
String username = args.optString(2);
String password = args.optString(3);
Log.d(
TAG,
"Connecting to " + host + ":" + port + " as " + username
);
ssh = SshClientBuilder.create()
.withHostname(host)
.withPort(port)
Expand All @@ -103,27 +108,48 @@ public void run() {
if (ssh.isConnected()) {
connectionID = username + "@" + host;

sftp = SftpClientBuilder.create().withClient(ssh).build();
try {
sftp = SftpClientBuilder.create().withClient(ssh).build();
} catch (IOException | SshException e) {
ssh.close();
callback.error(
"Failed to initialize SFTP subsystem: " + errMessage(e)
);
Log.e(TAG, "Failed to initialize SFTP subsystem", e);
return;
}

try {
sftp.getSubsystemChannel().setCharsetEncoding("UTF-8");
} catch (UnsupportedEncodingException | SshException e) {
// Fallback to default encoding if UTF-8 fails
Log.w(
TAG,
"Failed to set UTF-8 encoding, falling back to default",
e
);
}
callback.success();
Log.d("connectUsingPassword", "Connected successfully");
Log.d(TAG, "Connected successfully to " + connectionID);
return;
}

callback.error("Cannot connect");
} catch (
UnresolvedAddressException
| SshException
| IOException
| PermissionDeniedException e
) {
callback.error(errMessage(e));
Log.e("connectUsingPassword", "Cannot connect", e);
callback.error("Failed to establish SSH connection");
} catch (UnresolvedAddressException e) {
callback.error("Cannot resolve host address");
Log.e(TAG, "Cannot resolve host address", e);
} catch (PermissionDeniedException e) {
callback.error("Authentication failed: " + e.getMessage());
Log.e(TAG, "Authentication failed", e);
} catch (SshException e) {
callback.error("SSH error: " + errMessage(e));
Log.e(TAG, "SSH error", e);
} catch (IOException e) {
callback.error("I/O error: " + errMessage(e));
Log.e(TAG, "I/O error", e);
} catch (Exception e) {
callback.error("Unexpected error: " + errMessage(e));
Log.e(TAG, "Unexpected error", e);
}
}
}
Expand All @@ -150,37 +176,73 @@ public void run() {
ContentResolver contentResolver = context.getContentResolver();
InputStream in = contentResolver.openInputStream(uri);

SshKeyPair keyPair = null;
try {
keyPair = SshKeyUtils.getPrivateKey(in, passphrase);
} catch (InvalidPassphraseException e) {
callback.error("Invalid passphrase for key file");
Log.e(TAG, "Invalid passphrase for key file", e);
return;
} catch (IOException e) {
callback.error("Could not read key file: " + errMessage(e));
Log.e(TAG, "Could not read key file", e);
return;
}

ssh = SshClientBuilder.create()
.withHostname(host)
.withPort(port)
.withUsername(username)
.withIdentities(SshKeyUtils.getPrivateKey(in, passphrase))
.withIdentities(keyPair)
.build();

if (ssh.isConnected()) {
connectionID = username + "@" + host;
sftp = SftpClientBuilder.create().withClient(ssh).build();
try {
sftp = SftpClientBuilder.create().withClient(ssh).build();
} catch (IOException | SshException e) {
ssh.close();
callback.error(
"Failed to initialize SFTP subsystem: " + errMessage(e)
);
Log.e(TAG, "Failed to initialize SFTP subsystem", e);
return;
}

try {
sftp.getSubsystemChannel().setCharsetEncoding("UTF-8");
} catch (UnsupportedEncodingException | SshException e) {
// Fallback to default encoding if UTF-8 fails
Log.w(
TAG,
"Failed to set UTF-8 encoding, falling back to default",
e
);
}
callback.success();
Log.d(TAG, "Connected successfully to " + connectionID);
return;
}

callback.error("Cannot connect");
} catch (
InvalidPassphraseException
| UnresolvedAddressException
| SshException
| IOException
| SecurityException
| PermissionDeniedException e
) {
callback.error(errMessage(e));
Log.e("connectUsingKeyFile", "Cannot connect", e);
callback.error("Failed to establish SSH connection");
} catch (UnresolvedAddressException e) {
callback.error("Cannot resolve host address");
Log.e(TAG, "Cannot resolve host address", e);
} catch (PermissionDeniedException e) {
callback.error("Authentication failed: " + e.getMessage());
Log.e(TAG, "Authentication failed", e);
} catch (SshException e) {
callback.error("SSH error: " + errMessage(e));
Log.e(TAG, "SSH error", e);
} catch (IOException e) {
callback.error("I/O error: " + errMessage(e));
Log.e(TAG, "I/O error", e);
} catch (SecurityException e) {
callback.error("Security error: " + errMessage(e));
Log.e(TAG, "Security error", e);
} catch (Exception e) {
callback.error("Unexpected error: " + errMessage(e));
Log.e(TAG, "Unexpected error", e);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/sidebarApps/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ async function uninstall(id) {
searchInput.value = "";
$searchResult.content = "";
updateHeight($searchResult);
if ($installed.collapsed) {
$installed.expand();
}
}

// Show Ad If Its Free Version, interstitial Ad(iad) is loaded.
Expand Down