diff --git a/docs/manual/OptionalTasks/ftp.html b/docs/manual/OptionalTasks/ftp.html index 93e45a5fd..5d582985e 100644 --- a/docs/manual/OptionalTasks/ftp.html +++ b/docs/manual/OptionalTasks/ftp.html @@ -77,7 +77,7 @@ coming from your ftp server (ls -l on the ftp prompt).
action
attribute has been specified as "site"
.
+ FTPClientConfig
remote system key.
*
* @param systemTypeKey the key to be set - BUT if blank
- * the default value of null will be kept.
+ * the default value of null (which signifies "autodetect") will be kept.
* @see org.apache.commons.net.ftp.FTPClientConfig
*/
public void setSystemTypeKey(FTPSystemType systemKey) {
@@ -1283,9 +1290,7 @@ public class FTP
}
/**
- * Delegate method for
- * FTPClientConfig.setDefaultDateFormatStr(String)
.
- *
+ * Sets the defaultDateFormatConfig attribute.
* @param defaultDateFormatConfig configuration to be set, unless it is
* null or empty string, in which case ignored.
* @see org.apache.commons.net.ftp.FTPClientConfig
@@ -1299,9 +1304,7 @@ public class FTP
}
/**
- * Delegate method for
- * FTPClientConfig.setRecentDateFormatStr(String)
.
- *
+ * Sets the recentDateFormatConfig attribute.
* @param recentDateFormatConfig configuration to be set, unless it is
* null or empty string, in which case ignored.
* @see org.apache.commons.net.ftp.FTPClientConfig
@@ -1315,9 +1318,7 @@ public class FTP
}
/**
- * Delegate method for
- * FTPClientConfig.setServerLanguageCode(String)
.
- *
+ * Sets the serverLanguageCode attribute.
* @param serverLanguageCodeConfig configuration to be set, unless it is
* null or empty string, in which case ignored.
* @see org.apache.commons.net.ftp.FTPClientConfig
@@ -1331,9 +1332,7 @@ public class FTP
}
/**
- * Delegate method for
- * FTPClientConfig.setServerTimeZoneId(String)
.
- *
+ * Sets the serverTimeZoneConfig attribute.
* @param serverTimeZoneConfig configuration to be set, unless it is
* null or empty string, in which case ignored.
* @see org.apache.commons.net.ftp.FTPClientConfig
@@ -1347,8 +1346,7 @@ public class FTP
}
/**
- * Delegate method for
- * FTPClientConfig.setShortMonthNames(String)
.
+ * Sets the shortMonthNamesConfig attribute
*
* @param shortMonthNamesConfig configuration to be set, unless it is
* null or empty string, in which case ignored.
@@ -1437,6 +1435,7 @@ public class FTP
return timestampGranularity;
}
/**
+ * Sets the timestampGranularity attribute
* @param timestampGranularity The timestampGranularity to set.
*/
public void setTimestampGranularity(Granularity timestampGranularity) {
@@ -1445,6 +1444,24 @@ public class FTP
}
this.timestampGranularity = timestampGranularity;
}
+ /**
+ * Sets the siteCommand attribute. This attribute
+ * names the command that will be executed if the action
+ * is "site".
+ * @param siteCommand The siteCommand to set.
+ */
+ public void setSiteCommand(String siteCommand) {
+ this.siteCommand = siteCommand;
+ }
+ /**
+ * Sets the initialSiteCommand attribute. This attribute
+ * names a site command that will be executed immediately
+ * after connection.
+ * @param initialSiteCommand The initialSiteCommand to set.
+ */
+ public void setInitialSiteCommand(String initialCommand) {
+ this.initialSiteCommand = initialCommand;
+ }
/**
* Checks to see that all required parameters are set.
*
@@ -1475,6 +1492,11 @@ public class FTP
throw new BuildException("chmod attribute must be set for chmod "
+ "action!");
}
+ if (action == SITE_CMD && siteCommand == null) {
+ throw new BuildException("sitecommand attribute must be set for site "
+ + "action!");
+ }
+
if (this.isConfigurationSet) {
try {
@@ -1486,10 +1508,10 @@ public class FTP
}
}
- protected void executeRetryable(RetryHandler h, Retryable r, String filename)
+ protected void executeRetryable(RetryHandler h, Retryable r, String descr)
throws IOException
{
- h.execute(r, filename);
+ h.execute(r, descr);
}
@@ -2239,12 +2261,33 @@ public class FTP
+ "mode: " + ftp.getReplyString());
}
}
+
+ // If an initial command was configured then send it.
+ // Some FTP servers offer different modes of operation,
+ // E.G. switching between a UNIX file system mode and
+ // a legacy file system.
+ if (this.initialSiteCommand != null) {
+ RetryHandler h = new RetryHandler(this.retriesAllowed, this);
+ final FTPClient lftp = ftp;
+ executeRetryable(h, new Retryable() {
+ public void execute() throws IOException {
+ doSiteCommand(lftp, FTP.this.initialSiteCommand);
+ }
+ }, "initial site command: "+ this.initialSiteCommand);
+ }
+
// For a unix ftp server you can set the default mask for all files
// created.
if (umask != null) {
- doSiteCommand(ftp, "umask " + umask);
+ RetryHandler h = new RetryHandler(this.retriesAllowed, this);
+ final FTPClient lftp = ftp;
+ executeRetryable(h, new Retryable() {
+ public void execute() throws IOException {
+ doSiteCommand(lftp, "umask " + umask);
+ }
+ }, "umask " + umask);
}
// If the action is MK_DIR, then the specified remote
@@ -2258,6 +2301,14 @@ public class FTP
makeRemoteDir(lftp, remotedir);
}
}, remotedir);
+ } else if (action == SITE_CMD) {
+ RetryHandler h = new RetryHandler(this.retriesAllowed, this);
+ final FTPClient lftp = ftp;
+ executeRetryable(h, new Retryable() {
+ public void execute() throws IOException {
+ doSiteCommand(lftp, FTP.this.siteCommand);
+ }
+ }, "Site Command: " + this.siteCommand);
} else {
if (remotedir != null) {
log("changing the remote directory", Project.MSG_VERBOSE);
@@ -2301,7 +2352,7 @@ public class FTP
private static final String[] VALID_ACTIONS = {
"send", "put", "recv", "get", "del", "delete", "list", "mkdir",
- "chmod", "rmdir"
+ "chmod", "rmdir", "site"
};
@@ -2337,6 +2388,8 @@ public class FTP
return MK_DIR;
} else if (actionL.equals("rmdir")) {
return RM_DIR;
+ } else if (actionL.equals("site")) {
+ return SITE_CMD;
}
return SEND_FILES;
}
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
index dbff54b38..827ddef32 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
@@ -866,5 +866,31 @@ public class FTPTest extends BuildFileTest{
fail("Retry forever specified, but failed.");
}
}
+
+ public void testInitialCommand() {
+ performCommandTest("test-initial-command", new int[] { 1,0 });
+ }
+ public void testSiteAction() {
+ performCommandTest("test-site-action", new int[] { 1,0 });
+ }
+
+ private void performCommandTest(String target, int[] expectedCounts) {
+ String[] messages = new String[]{
+ "Doing Site Command: umask 222",
+ "Failed to issue Site Command: umask 222",
+ };
+ LogCounter counter = new LogCounter();
+ for (int i=0; i < messages.length; i++) {
+ counter.addLogMessageToSearch(messages[i]);
+ }
+
+ getProject().addBuildListener(counter);
+ getProject().executeTarget(target);
+ for (int i=0; i < messages.length; i++) {
+ assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
+ }
+
+ }
+
}