You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Kyle Adams <ka...@gfs.com> on 2002/09/12 16:21:59 UTC

[PATCH] 12576 FTP creation of remote directories

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH] 12576 FTP creation of remote directories

Posted by Stefan Bodewig <bo...@apache.org>.
Kyle, 

do you see any way to store the CWD before creating the directory tree
and change back to that when you are done (probably in a finally
clause).  This is the only problem I can identify at first glance.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>