This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new f842cf9  Add FTPClient.mdtmCalendar(String).
f842cf9 is described below

commit f842cf95813c083f22b53497021af8e0d0965f57
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Feb 8 20:19:05 2021 -0500

    Add FTPClient.mdtmCalendar(String).
---
 src/changes/changes.xml                            |  5 ++++-
 .../java/org/apache/commons/net/ftp/FTPClient.java | 21 +++++++++++++++++
 .../org/apache/commons/net/ftp/FTPSClientTest.java | 26 ++++++++++++++++++++--
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2d908e9..7d77395 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,9 +71,12 @@ The <action> type attribute can be add,update,fix,remove.
            <action type="update" dev="ggregory" due-to="Gary Gregory">
             Add and use SocketClient.applySocketAttributes().
             </action>
-            <action type="update" dev="ggregory" due-to="Dependabot">
+            <action type="update" dev="ggregory" due-to="Gary Gregory">
             Add FTPClient.hasFeature(FTPCmd).
             </action>
+            <action type="update" dev="ggregory" due-to="Gary Gregory">
+            Add FTPClient.mdtmCalendar(String).
+            </action>
             <!-- UPDATE -->
             <action type="update" dev="ggregory" due-to="Dependabot">
             Bump actions/checkout from v2.3.3 to v2.3.4 #69.
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java 
b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index 68f1696..f1891b7 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -35,6 +35,7 @@ import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
@@ -2901,6 +2902,26 @@ public class FTPClient extends FTP implements 
Configurable {
      * GMT, but not all FTP servers honor this.
      *
      * @param pathname The file path to query.
+     * @return A Calendar representing the last file modification time, may be 
{@code null}.
+     * The Calendar timestamp will be null if a parse error occurs.
+     * @throws IOException if an I/O error occurs.
+     * @since 3.8.0
+     */
+    public Calendar mdtmCalendar(final String pathname) throws IOException {
+        final String modificationTime = getModificationTime(pathname);
+        if (modificationTime != null) {
+            return MLSxEntryParser.parseGMTdateTime(modificationTime);
+        }
+        return null;
+    }
+
+    /**
+     * Issue the FTP MDTM command (not supported by all servers) to retrieve 
the last
+     * modification time of a file. The modification string should be in the
+     * ISO 3077 form "YYYYMMDDhhmmss(.xxx)?". The timestamp represented should 
also be in
+     * GMT, but not all FTP servers honor this.
+     *
+     * @param pathname The file path to query.
      * @return A FTPFile representing the last file modification time, may be 
{@code null}.
      * The FTPFile timestamp will be null if a parse error occurs.
      * @throws IOException if an I/O error occurs.
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java 
b/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
index 14f5880..602a8f1 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
@@ -25,6 +25,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.SocketException;
 import java.net.URL;
+import java.util.Calendar;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.output.NullOutputStream;
@@ -240,6 +241,24 @@ public class FTPSClientTest {
     }
 
     @Test
+    public void testMdtmCalendar() throws SocketException, IOException {
+        testMdtmCalendar("/file.txt");
+    }
+
+    private void testMdtmCalendar(final String pathname) throws 
SocketException, IOException {
+        final FTPSClient client = loginClient();
+        try {
+            // do it twice
+            final Calendar mdtmCalendar1 = client.mdtmCalendar(pathname);
+            final Calendar mdtmCalendar2 = client.mdtmCalendar(pathname);
+            assertNotNull(mdtmCalendar1);
+            assertNotNull(mdtmCalendar2);
+            assertEquals(mdtmCalendar1, mdtmCalendar2);
+        } finally {
+            client.disconnect();
+        }
+    }
+
     public void testMdtmFile() throws SocketException, IOException {
         testMdtmFile("/file.txt");
     }
@@ -248,8 +267,11 @@ public class FTPSClientTest {
         final FTPSClient client = loginClient();
         try {
             // do it twice
-            assertNotNull(client.mdtmFile(pathname));
-            assertNotNull(client.mdtmFile(pathname));
+            final FTPFile mdtmFile1 = client.mdtmFile(pathname);
+            final FTPFile mdtmFile2 = client.mdtmFile(pathname);
+            assertNotNull(mdtmFile1);
+            assertNotNull(mdtmFile2);
+            assertEquals(mdtmFile1, mdtmFile2);
         } finally {
             client.disconnect();
         }

Reply via email to