Skip to content

Commit 98f1b77

Browse files
committed
68773: initial experiment to support enabling secure data channel for FTPS
1 parent a1bfbdc commit 98f1b77

File tree

1 file changed

+21
-0
lines changed
  • src/main/org/apache/tools/ant/taskdefs/optional/net

1 file changed

+21
-0
lines changed

src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public class FTP extends Task implements FTPTaskConfig {
116116
private String password;
117117
private String account;
118118
private boolean useFtps = false;
119+
private boolean useSecureDataChannel = false;
119120
private HostnameVerifier hostnameVerifier;
120121
private File listing;
121122
private boolean binary = true;
@@ -1277,6 +1278,15 @@ public void setUseFtps(boolean useFtps) {
12771278
this.useFtps = useFtps;
12781279
}
12791280

1281+
/**
1282+
* Whether to use secure data channel when using FTPS
1283+
*
1284+
* @since 1.10.15
1285+
*/
1286+
public void setUseSecureDataChannel(boolean useSecureDataChannel) {
1287+
this.useSecureDataChannel = useSecureDataChannel;
1288+
}
1289+
12801290
public void add(HostnameVerifier hostnameVerifier) {
12811291
this.hostnameVerifier = hostnameVerifier;
12821292
}
@@ -2575,6 +2585,17 @@ public void execute() throws BuildException {
25752585
ftp.getReplyString());
25762586
}
25772587
}
2588+
// if it is FTPS and secure data channel is desired, then we exec "PROT P"
2589+
// command to enable secure data channel, for the lifetime of this client
2590+
if (useFtps && useSecureDataChannel) {
2591+
FTPSClient ftps = (FTPSClient) ftp;
2592+
try {
2593+
ftps.execPROT("P"); // P implies PRIVATE and enables encryption
2594+
} catch (IOException e) {
2595+
throw new BuildException("failed to enable secure data channel: " + e, e);
2596+
}
2597+
log("enabled secure data channel", Project.MSG_VERBOSE);
2598+
}
25782599

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

0 commit comments

Comments
 (0)