You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rw...@apache.org on 2009/04/14 03:42:02 UTC

svn commit: r764660 - in /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp: FTP.java FTPClient.java FTPCommand.java

Author: rwinston
Date: Tue Apr 14 01:42:02 2009
New Revision: 764660

URL: http://svn.apache.org/viewvc?rev=764660&view=rev
Log:
NET-245: Apply MFMT patch submitted by Shikhar

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=764660&r1=764659&r2=764660&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java Tue Apr 14 01:42:02 2009
@@ -1162,7 +1162,30 @@
     {
         return sendCommand(FTPCommand.MDTM, file);
     }
-
+    
+    
+    /**
+     * A convenience method to send the FTP MFMT command to the server,
+     * receive the reply, and return the reply code.
+     * <p>
+     * @param pathname The pathname for which mtime is to be changed
+     * @param timeval Timestamp in <code>YYYYMMDDhhmmss</code> format
+     * @return The reply code received from the server.
+     * @exception FTPConnectionClosedException
+     *      If the FTP server prematurely closes the connection as a result
+     *      of the client being idle or some other reason causing the server
+     *      to send FTP reply code 421.  This exception may be caught either
+     *      as an IOException or independently as itself.
+     * @exception IOException  If an I/O error occurs while either sending the
+     *      command or receiving the server reply.
+     * @see <a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04">http://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
+     **/
+    public int mfmt(String pathname, String timeval) throws IOException 
+    {
+    	return sendCommand(FTPCommand.MFMT, timeval + " " + pathname);
+    }
+    
+    
     /***
      * A convenience method to send the FTP RNFR command to the server,
      * receive the reply, and return the reply code.

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=764660&r1=764659&r2=764660&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java Tue Apr 14 01:42:02 2009
@@ -625,6 +625,7 @@
      ***/
     public boolean login(String username, String password) throws IOException
     {
+    	
         user(username);
 
         if (FTPReply.isPositiveCompletion(_replyCode))
@@ -2402,7 +2403,29 @@
         return null;
     }
 
-
+    
+    /**
+     * Issue the FTP MFMT command (not supported by all servers) which sets the last
+     * modified time of a file.
+     * 
+     * The timestamp should be in the form <code>YYYYMMDDhhmmss</code>. It should also
+     * be in GMT, but not all servers honour this.
+     * 
+     * An FTP server would indicate its support of this feature by including "MFMT"
+     * in its response to the FEAT command, which may be retrieved by FTPClient.features()
+     * 
+     * @param pathname The file path for which last modified time is to be changed.
+     * @param timeval The timestamp to set to, in <code>YYYYMMDDhhmmss</code> format. 
+     * @return true if successfully set, false if not
+     * @throws IOException if an I/O error occurs.
+     * @see <a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04">http://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
+     */
+    public boolean setModificationTime(String pathname, String timeval) throws IOException {
+        return (FTPReply.isPositiveCompletion(mfmt(pathname, timeval));
+        		
+    }
+    
+    
     /**
      * Set the internal buffer size.
      *  

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java?rev=764660&r1=764659&r2=764660&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java Tue Apr 14 01:42:02 2009
@@ -32,7 +32,6 @@
 public final class FTPCommand
 {
 
-
     public static final int USER = 0;
     public static final int PASS = 1;
     public static final int ACCT = 2;
@@ -70,6 +69,7 @@
     public static final int MDTM = 33;
     /** @since 2.1 */
     public static final int FEAT = 34;
+    public static final int MFMT = 35;
     
     public static final int USERNAME = USER;
     public static final int PASSWORD = PASS;
@@ -105,9 +105,10 @@
     //public static final int HELP = HELP;
     //public static final int NOOP = NOOP;
     /** @since 2.0 */
-    public static final int MOD_TIME = MDTM;
+    public static final int GET_MOD_TIME = MDTM;
     /** @since 2.1 */
     public static final int FEATURES = FEAT;
+    public static final int SET_MOD_TIME = MFMT;
     
     // Cannot be instantiated
     private FTPCommand()
@@ -117,7 +118,7 @@
                                           "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT",
                                           "PASV", "TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO",
                                           "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST",
-                                          "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT"
+                                          "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT", "MFMT"
                                       };
 
     /**