Skip to content
Open
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
31 changes: 25 additions & 6 deletions src/plugins/ftp/src/android/com/foxdebug/ftp/Ftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public void connect(JSONArray args, CallbackContext callback) {
connect(args, callback, false);
}

private FTPClient createClient(String securityType) {
// explicit FTPS: AUTH TLS on the normal port
return "ftps".equals(securityType) ? new FTPSClient(false) : new FTPClient();
}

public void connect(
JSONArray args,
CallbackContext callback,
Expand All @@ -93,19 +98,25 @@ public void run() {
String host = args.optString(0);
String username = args.optString(2);
String password = args.optString(3);
String defaultPath = args.optString(4);
// order must match www/ftp.js connect()
String connectionMode = args.optString(4);
String securityType = args.optString(5);
String connectionMode = args.optString(6);
String encryption = args.optString(7);
String encoding = args.optString(8);
String encoding = args.optString(6);
String ftpId = getFtpId(host, port, username);
FTPClient ftp = null;

try {
if (ftpProfiles.containsKey(ftpId)) {
ftp = ftpProfiles.get(ftpId);
reply = ftp.getReplyCode();
if (ftp.isConnected() && FTPReply.isPositiveCompletion(reply)) {
// ftpId ignores security, so don't reuse a client of the other type
boolean sameSecurity =
(ftp instanceof FTPSClient) == "ftps".equals(securityType);
if (
sameSecurity &&
ftp.isConnected() &&
FTPReply.isPositiveCompletion(reply)
) {
ftp.setControlEncoding("UTF-8");
ftp.setAutodetectUTF8(true);
System.setProperty("ftp.client.encoding", "UTF-8");
Expand All @@ -118,9 +129,11 @@ public void run() {
Log.d("FTP", "FTPClient (" + ftpId + ") is not connected");
ftp.disconnect();
Log.d("FTP", "FTPClient (" + ftpId + ") disconnecting...");
ftp = createClient(securityType);
ftpProfiles.put(ftpId, ftp);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
} else {
Log.d("FTP", "Creating new FTPClient (" + ftpId + ")");
ftp = new FTPClient();
ftp = createClient(securityType);
ftpProfiles.put(ftpId, ftp);
}

Expand Down Expand Up @@ -149,6 +162,12 @@ public void run() {
return;
}

if (ftp instanceof FTPSClient) {
// RFC 4217: protect the data channel too
((FTPSClient) ftp).execPBSZ(0);
((FTPSClient) ftp).execPROT("P");
}

ftp.setListHiddenFiles(true);
ftpProfiles.put(ftpId, ftp);
Log.d("FTP", "FTPClient (" + ftpId + ") connected");
Expand Down
Loading