commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shikhar Bhushan (JIRA)" <j...@apache.org>
Subject [jira] Commented: (NET-245) FTP: MFMT support
Date Thu, 09 Apr 2009 23:36:12 GMT

    [ https://issues.apache.org/jira/browse/NET-245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12697687#action_12697687
] 

Shikhar Bhushan commented on NET-245:
-------------------------------------

This is a patch for adding support for the MFMT command. I tested this against proftpd which
supports the feature.

Index: FTPClient.java
===================================================================
--- FTPClient.java	(revision 763793)
+++ FTPClient.java	(working copy)
@@ -2402,7 +2402,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(mdtm(pathname))
+        		&& getReplyString().contains(timeval));
+    }    
 
+    
     /**
      * Set the internal buffer size.
      *  
Index: FTPCommand.java
===================================================================
--- FTPCommand.java	(revision 763793)
+++ FTPCommand.java	(working copy)
@@ -70,6 +70,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 +106,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 +119,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"
                                       };
 
     /**
Index: FTP.java
===================================================================
--- FTP.java	(revision 763793)
+++ FTP.java	(working copy)
@@ -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.
Index: FTPClient.java
===================================================================
--- FTPClient.java	(revision 763793)
+++ FTPClient.java	(working copy)
@@ -2402,8 +2402,30 @@
         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))
+        		&& getReplyString().contains(timeval));
+    }
+    
+    
+    /**
      * Set the internal buffer size.
      *  
      * @param bufSize The size of the buffer
Index: FTPCommand.java
===================================================================
--- FTPCommand.java	(revision 763793)
+++ FTPCommand.java	(working copy)
@@ -70,6 +70,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 +106,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 +119,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"
                                       };
 
     /**
Index: FTP.java
===================================================================
--- FTP.java	(revision 763793)
+++ FTP.java	(working copy)
@@ -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.
Index: FTPClient.java
===================================================================
--- FTPClient.java	(revision 763793)
+++ FTPClient.java	(working copy)
@@ -2402,8 +2402,30 @@
         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))
+        		&& getReplyString().contains(timeval));
+    }
+    
+    
+    /**
      * Set the internal buffer size.
      *  
      * @param bufSize The size of the buffer
Index: FTPCommand.java
===================================================================
--- FTPCommand.java	(revision 763793)
+++ FTPCommand.java	(working copy)
@@ -70,6 +70,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 +106,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 +119,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"
                                       };
 
     /**
Index: FTP.java
===================================================================
--- FTP.java	(revision 763793)
+++ FTP.java	(working copy)
@@ -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.


> FTP: MFMT support
> -----------------
>
>                 Key: NET-245
>                 URL: https://issues.apache.org/jira/browse/NET-245
>             Project: Commons Net
>          Issue Type: Wish
>    Affects Versions: Nightly Builds, 2.1
>            Reporter: ArtemGr
>
> A lot of modern FTP servers support time modification via MFMT.
> This is especially useful for file synchronization.
> http://www.omz13.com/downloads/draft-somers-ftp-mfxx-00.html#anchor8
> http://forum.filezilla-project.org/viewtopic.php?f=6&t=6115

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message