You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jk...@apache.org on 2019/07/12 15:01:11 UTC

[ant] 01/02: Bugzilla 63252 FTP prevent No Transfer Timeout during long listings by Eugene Adell

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

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

commit b719dcff3d6cd3e79705dcbcb9357579ae8ff711
Author: jkf <jm...@famkruithof.net>
AuthorDate: Fri Jul 12 16:24:54 2019 +0200

    Bugzilla 63252 FTP prevent No Transfer Timeout during long listings by Eugene Adell
---
 .../tools/ant/taskdefs/optional/net/FTP.java       | 48 ++++++++++++++++++++++
 1 file changed, 48 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 ad16f41..33d27ec 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
@@ -146,6 +146,9 @@ public class FTP extends Task implements FTPTaskConfig {
     private String initialSiteCommand = null;
     private boolean enableRemoteVerification = true;
     private int dataTimeout = -1;
+    private int wakeUpTransferInterval = -1;
+    private long lastWakeUpTime = 0;
+
 
     protected static final String[] ACTION_STRS = { //NOSONAR
         "sending",
@@ -547,6 +550,14 @@ public class FTP extends Task implements FTPTaskConfig {
                             }
                         }
                     }
+                    if(wakeUpTransferInterval > 0) {
+                        if(wakeUpTransferIntervalExpired()) {
+                            getProject().log("wakeUpTransferInterval is reached, trigger a data connection " , Project.MSG_DEBUG);
+                            // send a minimalist command to trigger a data connection
+                            ftp.listFiles(file.getName());
+                        }
+                    }
+
                 }
                 ftp.changeToParentDirectory();
             } catch (FTPConnectionClosedException ftpcce) {
@@ -1711,6 +1722,21 @@ public class FTP extends Task implements FTPTaskConfig {
     }
 
     /**
+     * Sets the time interval when we should automatically
+     * call a command triggering a transfer
+     * The parameter is in seconds
+     *
+     * @param wakeUpTransferInterval int
+     * @since Ant 1.10.6
+     */
+    public void setWakeUpTransferInterval(int wakeUpTransferInterval) {
+        if(wakeUpTransferInterval > 0) {
+            this.wakeUpTransferInterval = wakeUpTransferInterval;
+        }
+    }
+
+
+    /**
      * Checks to see that all required parameters are set.
      *
      * @throws BuildException if the configuration is not valid.
@@ -2438,6 +2464,28 @@ public class FTP extends Task implements FTPTaskConfig {
     }
 
     /**
+     * checks if the wake up interval is expired
+     */
+    private boolean wakeUpTransferIntervalExpired() {
+        boolean result = false;
+
+        // on the first call, initialize the keep-alive mechanism
+        // by storing the current date
+        if(lastWakeUpTime == 0) {
+            lastWakeUpTime = (new Date()).getTime();
+        }
+        else {
+            long currentTime = (new Date()).getTime();
+            if(currentTime > (lastWakeUpTime + wakeUpTransferInterval*1000)) {
+                lastWakeUpTime = currentTime;
+                result = true;
+            }
+        }
+
+        return result;
+    }
+
+    /**
      * Runs the task.
      *
      * @throws BuildException if the task fails or is not configured