diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index f9e98e6e5..507fc6bd4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -473,6 +473,7 @@ public class Ant extends Task { Method cloneM = c.getMethod("clone", new Class[0]); if (cloneM != null) { copy = cloneM.invoke(orig, new Object[0]); + log("Adding clone of reference " + oldKey, Project.MSG_DEBUG); } } catch (Exception e) { // not Clonable 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 e8c6a2df1..233a47596 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 @@ -67,6 +67,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Locale; +import java.util.StringTokenizer; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; @@ -101,6 +102,7 @@ import org.apache.tools.ant.util.FileUtils; * @author Glenn McAllister * glennm@ca.ibm.com * @author Magesh Umasankar + * @author Kyle Adams * @since Ant 1.3 */ public class FTP @@ -938,23 +940,41 @@ public class FTP */ protected void makeRemoteDir(FTPClient ftp, String dir) throws IOException, BuildException { + String workingDirectory = ftp.printWorkingDirectory(); if (verbose) { - log("creating directory: " + dir); + log("Creating directory: " + dir); } - - if (!ftp.makeDirectory(dir)) { - // codes 521, 550 and 553 can be produced by FTP Servers - // to indicate that an attempt to create a directory has - // failed because the directory already exists. - handleMkDirFailure(ftp); - if (verbose) { - log("directory already exists"); - } - } else { - if (verbose) { - log("directory created OK"); + if (dir.indexOf("/") == 0) { + ftp.changeWorkingDirectory("/"); + } + String subdir = new String(); + StringTokenizer st = new StringTokenizer(dir, "/"); + while (st.hasMoreTokens()) { + subdir = st.nextToken(); + log("Checking " + subdir, Project.MSG_DEBUG); + if (!ftp.changeWorkingDirectory(subdir)) { + if(!ftp.makeDirectory(subdir)) { + // codes 521, 550 and 553 can be produced by FTP Servers + // to indicate that an attempt to create a directory has + // failed because the directory already exists. + int rc = ftp.getReplyCode(); + if (!(ignoreNoncriticalErrors && (rc == 550 || rc == 553 || rc==521))) { + throw new BuildException("could not create directory: " + ftp.getReplyString()); + } + if (verbose) { + log("Directory already exists"); + } + } else { + if (verbose) { + log("Directory created OK"); + } + ftp.changeWorkingDirectory(subdir); + } } } + if (workingDirectory != null) { + ftp.changeWorkingDirectory(workingDirectory); + } } /**