This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new 98f1b774f 68773: initial experiment to support enabling secure data 
channel for FTPS
98f1b774f is described below

commit 98f1b774fb836a903ac3942c5b1c268734cb7b53
Author: Jaikiran Pai <jaiki...@apache.org>
AuthorDate: Sat Mar 16 18:00:30 2024 +0530

    68773: initial experiment to support enabling secure data channel for FTPS
---
 .../apache/tools/ant/taskdefs/optional/net/FTP.java | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java 
b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
index 8662993fd..d435a355a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
@@ -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;
@@ -1277,6 +1278,15 @@ public class FTP extends Task implements FTPTaskConfig {
         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;
     }
@@ -2575,6 +2585,17 @@ public class FTP extends Task implements FTPTaskConfig {
                         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,

Reply via email to