ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
Date Thu, 21 Mar 2002 09:47:35 GMT
bodewig     02/03/21 01:47:35

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks ftp.html
               src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
  Log:
  add umask and chmod capability to <ftp>
  
  Submitted by:	Jay van der Meer <jvandermeer2@comcast.net>
  
  Revision  Changes    Path
  1.228     +5 -1      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.227
  retrieving revision 1.228
  diff -u -r1.227 -r1.228
  --- WHATSNEW	21 Mar 2002 09:17:01 -0000	1.227
  +++ WHATSNEW	21 Mar 2002 09:47:35 -0000	1.228
  @@ -232,7 +232,11 @@
     to the standard Java 1.4 doclet. The element is ignored when not running
     on Java 1.4.
   
  -* <java>'s source attribute is now enabled for jikes as well.
  +* <javac>'s source attribute is now enabled for jikes as well.
  +
  +* <ftp> can now chmod files on a remote server that supports
  +  "site chmod" as well as set the umask before transfering files if
  +  the server supports "site umask".
   
   Changes from Ant 1.4 to Ant 1.4.1
   ===========================================
  
  
  
  1.10      +14 -2     jakarta-ant/docs/manual/OptionalTasks/ftp.html
  
  Index: ftp.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/ftp.html,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ftp.html	3 Feb 2002 22:09:09 -0000	1.9
  +++ ftp.html	21 Mar 2002 09:47:35 -0000	1.10
  @@ -66,7 +66,7 @@
       <td valign="top">action</td>
       <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
 
                        Currently supports &quot;put&quot;, &quot;get&quot;,
  -                     &quot;del&quot;, &quot;list&quot; and &quot;mkdir&quot;.</td>
  +                     &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;
and &quot;mkdir&quot;.</td>
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  @@ -106,6 +106,18 @@
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  +    <td valign="top">umask</td>
  +    <td valign="top">sets the default file permissions for new files,
  +                     unix only.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">chmod</td>
  +    <td valign="top">sets or changes file permissions for new or existing files,
  +      unix only. If used with a put action, chmod will be issued for each file.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
       <td valign="top">listing</td>
       <td valign="top">the file to write results of the &quot;list&quot; action.
                        Required for the &quot;list&quot; action, ignored otherwise.</td>
  @@ -251,7 +263,7 @@
   directory.  As with all other actions, the directory separator character must be correct
   according to the desires of the FTP server.</p>
   <hr>
  -<p align="center">Copyright &copy; 2001 Apache Software Foundation. All rights
  +<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All
rights
   Reserved.</p>
   
   </body>
  
  
  
  1.17      +77 -7     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FTP.java	10 Jan 2002 13:59:37 -0000	1.16
  +++ FTP.java	21 Mar 2002 09:47:35 -0000	1.17
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -86,6 +86,7 @@
    *   <li><strong>get</strong> - retrive files from a remote server.</li>
    *   <li><strong>del</strong> - delete files from a remote server.</li>
    *   <li><strong>list</strong> - create a file listing.</li>
  + *   <li><strong>chmod</strong> - change unix file permissions.</li>
    * </ul>
    *
    * <strong>Note:</strong>
  @@ -108,6 +109,7 @@
       protected final static int DEL_FILES    = 2;
       protected final static int LIST_FILES   = 3;
       protected final static int MK_DIR       = 4;
  +    protected final static int CHMOD        = 5;
   
       private String remotedir;
       private String server;
  @@ -127,13 +129,16 @@
       private boolean skipFailedTransfers=false;
       private int skipped=0;
       private boolean ignoreNoncriticalErrors=false;
  +    private String chmod = null;
  +    private String umask = null;
   
       protected final static String[] ACTION_STRS = {
           "sending",
           "getting",
           "deleting",
           "listing",
  -        "making directory"
  +        "making directory",
  +        "chmod"
       };
   
       protected final static String[] COMPLETED_ACTION_STRS = {
  @@ -141,7 +146,8 @@
           "retrieved",
           "deleted",
           "listed",
  -        "created directory"
  +        "created directory",
  +        "mode changed"
       };
   
       protected class FTPDirectoryScanner extends DirectoryScanner {
  @@ -337,6 +343,22 @@
       }
   
       /**
  +     * Sets the file permission mode (Unix only) for files sent to the server.
  +    */
  +
  +    public void setChmod(String theMode) {
  +        this.chmod = theMode;
  +    }
  +
  +    /**
  +     * Sets the default mask for file creation on a unix server.
  +    */
  +
  +    public void setUmask(String theUmask) {
  +        this.umask = theUmask;
  +    }
  +
  +    /**
        * Adds a set of files (nested fileset attribute).
        */
       public void addFileset(FileSet set) {
  @@ -362,7 +384,7 @@
   
       /**
        * Sets the FTP action to be taken.  Currently accepts "put", "get",
  -     * "del", "mkdir" and "list".
  +     * "del", "mkdir", "chmod" and "list".
        */
       public void setAction(Action action) throws BuildException {
           this.action = action.getAction();
  @@ -415,9 +437,13 @@
               throw new BuildException("listing attribute must be set for list action!");
           }
   
  -        if( action == MK_DIR && remotedir == null ) {
  +        if (action == MK_DIR && remotedir == null) {
               throw new BuildException("remotedir attribute must be set for mkdir action!");
           }
  +
  +        if (action == CHMOD && chmod == null) {
  +            throw new BuildException("chmod attribute must be set for chmod action!");
  +        }
       }
   
       /**
  @@ -480,6 +506,12 @@
                   break;
               }
   
  +            case CHMOD: {
  +                 doSiteCommand(ftp,"chmod " + chmod + " " + dsfiles[i]);
  +                 transferred++;
  +                 break;
  +            }
  +
               default: {
                   throw new BuildException("unknown ftp action " + action );
               }
  @@ -621,6 +653,32 @@
       }
   
       /**
  +     * Sends a site command to the ftp server
  +     */
  +    protected void doSiteCommand(FTPClient ftp, String TheCMD)
  +        throws IOException, BuildException {
  +        boolean rc;
  +        String MyReply[] = null;
  +
  +        log("Doing Site Command: " + TheCMD,Project.MSG_VERBOSE);
  +
  +        rc = ftp.sendSiteCommand(TheCMD);
  +
  +        if (rc == false) {
  +            log("Failed to issue Site Command: " + TheCMD,Project.MSG_WARN);
  +        } else {
  +
  +            MyReply = ftp.getReplyStrings();
  +
  +            for (int x=0; x < MyReply.length; x++) {
  +                if (MyReply[x].indexOf("200") == -1) {
  +                    log(MyReply[x],Project.MSG_WARN);
  +                }
  +            }
  +        }
  +    }
  +
  +    /**
        * Sends a single file to the remote host.
        * <code>filename</code> may contain a relative path specification.
        * When this is the case, <code>sendFile</code> will attempt to create
  @@ -666,7 +724,9 @@
   
               }
               else {
  -
  +                if (chmod != null) { // see if we should issue a chmod command
  +                  doSiteCommand(ftp,"chmod " + chmod + " " + filename);
  +                }
                   log("File " + file.getAbsolutePath() +
                       " copied to " + server,
                       Project.MSG_VERBOSE);
  @@ -891,6 +951,13 @@
                   }
               }
   
  +            // For a unix ftp server you can set the default mask for all files
  +            // created.
  +
  +            if (umask != null) {
  +               doSiteCommand(ftp,"umask " + umask);
  +            }
  +
               // If the action is MK_DIR, then the specified remote directory is the
               // directory to create.
   
  @@ -940,7 +1007,8 @@
       public static class Action extends EnumeratedAttribute {
   
           private final static String[] validActions = {
  -            "send", "put", "recv", "get", "del", "delete", "list", "mkdir"
  +            "send", "put", "recv", "get", "del", "delete", "list", "mkdir", 
  +            "chmod"
           };
   
           public String[] getValues() {
  @@ -960,6 +1028,8 @@
                   return DEL_FILES;
               } else if (actionL.equals("list")) {
                   return LIST_FILES;
  +            } else if (actionL.equals("chmod")) {
  +                return CHMOD;
               } else if (actionL.equals("mkdir")) {
                   return MK_DIR;
               }
  
  
  

--
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