From 879077fa37b76ac953c13ae4c6e0f62c59c69ffa Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 21 Mar 2002 09:47:35 +0000 Subject: [PATCH] add umask and chmod capability to Submitted by: Jay van der Meer git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271938 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 6 +- docs/manual/OptionalTasks/ftp.html | 16 +++- .../tools/ant/taskdefs/optional/net/FTP.java | 84 +++++++++++++++++-- 3 files changed, 96 insertions(+), 10 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 6c61419d7..a51599cb7 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -232,7 +232,11 @@ Other changes: to the standard Java 1.4 doclet. The element is ignored when not running on Java 1.4. -* 's source attribute is now enabled for jikes as well. +* 's source attribute is now enabled for jikes as well. + +* 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 =========================================== diff --git a/docs/manual/OptionalTasks/ftp.html b/docs/manual/OptionalTasks/ftp.html index 1ef7811fe..77a7009f9 100644 --- a/docs/manual/OptionalTasks/ftp.html +++ b/docs/manual/OptionalTasks/ftp.html @@ -66,7 +66,7 @@ the code to parse MS-DOS listings -any takers? action the ftp action to perform, defaulting to "send". Currently supports "put", "get", - "del", "list" and "mkdir". + "del", "list", "chmod" and "mkdir". No @@ -105,6 +105,18 @@ the code to parse MS-DOS listings -any takers? Defaults to "/". No + + umask + sets the default file permissions for new files, + unix only. + No + + + chmod + 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. + No + listing the file to write results of the "list" action. @@ -251,7 +263,7 @@ remotedir attribute.

directory. As with all other actions, the directory separator character must be correct according to the desires of the FTP server.


-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

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 57a9d4ab8..87ad7ea0d 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 @@ -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 @@ import java.util.Vector; *
  • get - retrive files from a remote server.
  • *
  • del - delete files from a remote server.
  • *
  • list - create a file listing.
  • + *
  • chmod - change unix file permissions.
  • * * * Note: @@ -108,6 +109,7 @@ public class FTP 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 @@ public class FTP 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 @@ public class FTP "retrieved", "deleted", "listed", - "created directory" + "created directory", + "mode changed" }; protected class FTPDirectoryScanner extends DirectoryScanner { @@ -336,6 +342,22 @@ public class FTP remoteFileSep = separator; } + /** + * 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). */ @@ -362,7 +384,7 @@ public class FTP /** * 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 @@ public class FTP 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 @@ public class FTP break; } + case CHMOD: { + doSiteCommand(ftp,"chmod " + chmod + " " + dsfiles[i]); + transferred++; + break; + } + default: { throw new BuildException("unknown ftp action " + action ); } @@ -620,6 +652,32 @@ public class FTP } } + /** + * 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. * filename may contain a relative path specification. @@ -666,7 +724,9 @@ public class FTP } 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 @@ public class FTP } } + // 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 class FTP 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 @@ public class FTP 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; }