Skip to content

Commit

Permalink
68773: initial experiment to support enabling secure data channel for…
Browse files Browse the repository at this point in the history
… FTPS
  • Loading branch information
jaikiran committed Mar 16, 2024
1 parent a1bfbdc commit 98f1b77
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public class FTP extends Task implements FTPTaskConfig {
private String password;
private String account;
private boolean useFtps = false;
private boolean useSecureDataChannel = false;
private HostnameVerifier hostnameVerifier;
private File listing;
private boolean binary = true;
Expand Down Expand Up @@ -1277,6 +1278,15 @@ public void setUseFtps(boolean useFtps) {
this.useFtps = useFtps;
}

/**
* Whether to use secure data channel when using FTPS
*
* @since 1.10.15
*/
public void setUseSecureDataChannel(boolean useSecureDataChannel) {
this.useSecureDataChannel = useSecureDataChannel;
}

public void add(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
}
Expand Down Expand Up @@ -2575,6 +2585,17 @@ public void execute() throws BuildException {
ftp.getReplyString());
}
}
// if it is FTPS and secure data channel is desired, then we exec "PROT P"
// command to enable secure data channel, for the lifetime of this client
if (useFtps && useSecureDataChannel) {
FTPSClient ftps = (FTPSClient) ftp;
try {
ftps.execPROT("P"); // P implies PRIVATE and enables encryption
} catch (IOException e) {
throw new BuildException("failed to enable secure data channel: " + e, e);
}
log("enabled secure data channel", Project.MSG_VERBOSE);
}

// If an initial command was configured then send it.
// Some FTP servers offer different modes of operation,
Expand Down

0 comments on commit 98f1b77

Please sign in to comment.