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 aa69cf7..7120f7d 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 @@ -143,6 +143,8 @@ public class FTP extends Task implements FTPTaskConfig { private String siteCommand = null; private String initialSiteCommand = null; private boolean enableRemoteVerification = true; + private int wakeUpTransferInterval = -1; + private long lastWakeUpTime = 0; protected static final String[] ACTION_STRS = { //NOSONAR "sending", @@ -546,6 +548,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 (IOException e) { @@ -1683,6 +1693,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. @@ -2410,6 +2435,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