ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kyle Adams" <kad...@gfs.com>
Subject [PATCH] 12576 FTP creation of remote directories
Date Thu, 12 Sep 2002 14:21:59 GMT
The attached patch handles remote directory creation iteratively,
creating any missing parent directories that are necessary to create the
entire path.

=================

--- ftp.java	2002-09-12 09:31:04.000000000 -0400
+++ FTP-modified.java	2002-09-12 09:47:20.000000000 -0400
@@ -866,23 +866,34 @@
      * @param dir The directory to create (format must be correct for
host
      *      type)
      */
-    protected void makeRemoteDir(FTPClient ftp, String dir)
-         throws IOException, BuildException {
+    protected void makeRemoteDir( FTPClient ftp, String dir )
+      throws IOException, BuildException {
         if (verbose) {
             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("subdir: " + 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.
+                    handleMkDirFailure(ftp);
+                    if (verbose) {
+                        log("directory already exists");
+                    }
+                } else {
+                    if (verbose) {
+                        log("directory created OK");
+                    }
+                    ftp.changeWorkingDirectory(subdir);
+                }
             }
         }
     }

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message