Skip to content
Permalink
Browse files
Add FTPClient.mdtmCalendar(String).
  • Loading branch information
garydgregory committed Feb 9, 2021
1 parent 8e5e359 commit f842cf95813c083f22b53497021af8e0d0965f57
Showing 3 changed files with 49 additions and 3 deletions.
@@ -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.
@@ -35,6 +35,7 @@
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;
@@ -2894,6 +2895,26 @@ public boolean makeDirectory(final String pathname) throws IOException
return FTPReply.isPositiveCompletion(mkd(pathname));
}

/**
* 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 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
@@ -25,6 +25,7 @@
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 void testListFilesPathNameRoot() throws SocketException, IOException {
}

@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 @@ private void testMdtmFile(final String pathname) throws SocketException, IOExcep
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();
}

0 comments on commit f842cf9

Please sign in to comment.