ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry V. Streepy, Jr." <stre...@healthlanguage.com>
Subject [PATCH] Updated FTP.java
Date Thu, 26 Jul 2001 17:55:53 GMT
I have made one enhancement and one bug fix to FTP.java.

1. The enhancement is to support a "mkdir" action.  With this action,
the specified "remotedir" is created using a normal FTP MKDIR command.

2. The bug fix changes the isUpToDate test to prevent a build failure
when the remote file doesn't exist and the action is SEND.

Hopefully others will find these changes useful.

Due to some problems with my source control system, I can't generate
a proper patch file. In the patch below, the file /tmp/FTP.java is
the latest version (1.6) from the ant CVS tree.  The second file is
the one with my additions.

Thanks.


*** /tmp/FTP.java       Thu Jul 26 11:46:45 2001
--- FTP.java    Thu Jul 26 11:33:25 2001
***************
*** 89,94 ****
--- 89,95 ----
      protected final static int GET_FILES    = 1;
      protected final static int DEL_FILES    = 2;
      protected final static int LIST_FILES   = 3;
+     protected final static int MK_DIR       = 4;

      private String remotedir;
      private String server;
***************
*** 110,123 ****
          "sending",
          "getting",
          "deleting",
!         "listing"
      };

      protected final static String[] COMPLETED_ACTION_STRS = {
          "sent",
          "retrieved",
          "deleted",
!         "listed"
      };

      protected class FTPDirectoryScanner extends DirectoryScanner {
--- 111,126 ----
          "sending",
          "getting",
          "deleting",
!         "listing",
!         "making directory",
      };

      protected final static String[] COMPLETED_ACTION_STRS = {
          "sent",
          "retrieved",
          "deleted",
!         "listed",
!         "directory created",
      };

      protected class FTPDirectoryScanner extends DirectoryScanner {
***************
*** 344,349 ****
--- 347,356 ----
          {
              this.action = LIST_FILES;
          }
+         else if (action.toLowerCase().equals("mkdir"))
+         {
+             this.action = MK_DIR;
+         }
          else
          {
              throw new BuildException("action " + action + " is not supported");
***************
*** 381,386 ****
--- 388,397 ----
          {
              throw new BuildException("listing attribute must be set for list action!");
          }
+
+         if( action == MK_DIR && remotedir == null ) {
+             throw new BuildException("remotedir attribute must be set for mkdir action!");
+         }
      }

      /**
***************
*** 390,396 ****
      protected int transferFiles(FTPClient ftp, FileSet fs)
          throws IOException, BuildException
      {
!         FileScanner ds;

          if (action == SEND_FILES) {
              ds = fs.getDirectoryScanner(project);
--- 401,407 ----
      protected int transferFiles(FTPClient ftp, FileSet fs)
          throws IOException, BuildException
      {
!         DirectoryScanner ds;

          if (action == SEND_FILES) {
              ds = fs.getDirectoryScanner(project);
***************
*** 550,565 ****
          log("checking date for " + remoteFile, Project.MSG_VERBOSE);

          FTPFile[] files = ftp.listFiles(remoteFile);
-         if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()))
-         {
-             throw new BuildException(
-                                      "could not date test remote file: " +
-                                      ftp.getReplyString());
-         }

          if (files == null)
          {
!             return false;
          }

          long remoteTimestamp = files[0].getTimestamp().getTime().getTime();
--- 561,580 ----
          log("checking date for " + remoteFile, Project.MSG_VERBOSE);

          FTPFile[] files = ftp.listFiles(remoteFile);

          if (files == null)
          {
!             // If we are sending files, then assume out of date.
!             // If we are getting files, then throw an error
!
!             if( action == SEND_FILES ) {
!                 log("Could not date test remote file: " + remoteFile
!                     + "assuming out of date.", Project.MSG_VERBOSE);
!                 return false;
!             } else {
!                 throw new BuildException("could not date test remote file: " +
!                                          ftp.getReplyString());
!             }
          }

          long remoteTimestamp = files[0].getTimestamp().getTime().getTime();
***************
*** 732,737 ****
--- 747,785 ----
      }

      /**
+      * Create the specified directory on the remote host.
+      * @param ftp The FTP client connection
+      * @param dir The directory to create (format must be correct for host type)
+      */
+     protected void makeRemoteDir( FTPClient ftp, String dir )
+         throws IOException, BuildException
+     {
+         if (verbose) {
+             log("creating directory: " + dir);
+         }
+
+         if( ! ftp.makeDirectory( dir ) ) {
+             // Both codes 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( rc != 550 && rc != 553 ) {
+                 throw new BuildException( "could not create directory: " +
+                                           ftp.getReplyString() );
+             }
+
+             if( verbose ) {
+                 log( "directory already exists" );
+             }
+         } else {
+             if( verbose ) {
+                 log( "directory created OK" );
+             }
+         }
+     }
+
+     /**
       * Runs the task.
       */
      public void execute()
***************
*** 786,805 ****
                  }
              }

!             if (remotedir != null)
!             {
!                 log("changing the remote directory", Project.MSG_VERBOSE);
!                 ftp.changeWorkingDirectory(remotedir);
!                 if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()))
                  {
!                     throw new BuildException(
!                                              "could not change remote directory: " +
!                                              ftp.getReplyString());
                  }
              }
-
-             log(ACTION_STRS[action] + " files");
-             transferFiles(ftp);

          }
          catch(IOException ex)
--- 834,862 ----
                  }
              }

!             // If the action is MK_DIR, then the specified remote directory is the
!             // directory to create.
!
!             if( action == MK_DIR ) {
!
!                 makeRemoteDir( ftp, remotedir );
!
!             } else {
!                 if (remotedir != null)
                  {
!                     log("changing the remote directory", Project.MSG_VERBOSE);
!                     ftp.changeWorkingDirectory(remotedir);
!                     if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()))
!                     {
!                         throw new BuildException(
!                                                  "could not change remote directory: " +
!                                                  ftp.getReplyString());
!                     }
!
!                     log(ACTION_STRS[action] + " files");
!                     transferFiles(ftp);
                  }
              }

          }
          catch(IOException ex)

-- 
Larry V. Streepy, Jr.
Chief Technical Officer and VP of Engineering

Health Language, Inc.  -- "We speak the language of healthcare"

970/626-5028 (office)           mailto:streepy@healthlanguage.com
970/626-4425 (fax)              http://www.healthlanguage.com

Mime
View raw message