Skip to content

Commit 44cec10

Browse files
author
Rory Winston
committed
NET-245: Apply MFMT patch submitted by Shikhar
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/NET_2_0@764660 13f79535-47bb-0310-9956-ffa450edef68
1 parent d0030de commit 44cec10

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

src/main/java/org/apache/commons/net/ftp/FTP.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,30 @@ public int mdtm(String file) throws IOException
11621162
{
11631163
return sendCommand(FTPCommand.MDTM, file);
11641164
}
1165-
1165+
1166+
1167+
/**
1168+
* A convenience method to send the FTP MFMT command to the server,
1169+
* receive the reply, and return the reply code.
1170+
* <p>
1171+
* @param pathname The pathname for which mtime is to be changed
1172+
* @param timeval Timestamp in <code>YYYYMMDDhhmmss</code> format
1173+
* @return The reply code received from the server.
1174+
* @exception FTPConnectionClosedException
1175+
* If the FTP server prematurely closes the connection as a result
1176+
* of the client being idle or some other reason causing the server
1177+
* to send FTP reply code 421. This exception may be caught either
1178+
* as an IOException or independently as itself.
1179+
* @exception IOException If an I/O error occurs while either sending the
1180+
* command or receiving the server reply.
1181+
* @see <a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04">http://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
1182+
**/
1183+
public int mfmt(String pathname, String timeval) throws IOException
1184+
{
1185+
return sendCommand(FTPCommand.MFMT, timeval + " " + pathname);
1186+
}
1187+
1188+
11661189
/***
11671190
* A convenience method to send the FTP RNFR command to the server,
11681191
* receive the reply, and return the reply code.

src/main/java/org/apache/commons/net/ftp/FTPClient.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ public boolean isRemoteVerificationEnabled()
625625
***/
626626
public boolean login(String username, String password) throws IOException
627627
{
628+
628629
user(username);
629630

630631
if (FTPReply.isPositiveCompletion(_replyCode))
@@ -2402,7 +2403,29 @@ public String getModificationTime(String pathname) throws IOException {
24022403
return null;
24032404
}
24042405

2405-
2406+
2407+
/**
2408+
* Issue the FTP MFMT command (not supported by all servers) which sets the last
2409+
* modified time of a file.
2410+
*
2411+
* The timestamp should be in the form <code>YYYYMMDDhhmmss</code>. It should also
2412+
* be in GMT, but not all servers honour this.
2413+
*
2414+
* An FTP server would indicate its support of this feature by including "MFMT"
2415+
* in its response to the FEAT command, which may be retrieved by FTPClient.features()
2416+
*
2417+
* @param pathname The file path for which last modified time is to be changed.
2418+
* @param timeval The timestamp to set to, in <code>YYYYMMDDhhmmss</code> format.
2419+
* @return true if successfully set, false if not
2420+
* @throws IOException if an I/O error occurs.
2421+
* @see <a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04">http://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
2422+
*/
2423+
public boolean setModificationTime(String pathname, String timeval) throws IOException {
2424+
return (FTPReply.isPositiveCompletion(mfmt(pathname, timeval));
2425+
2426+
}
2427+
2428+
24062429
/**
24072430
* Set the internal buffer size.
24082431
*

src/main/java/org/apache/commons/net/ftp/FTPCommand.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
public final class FTPCommand
3333
{
3434

35-
3635
public static final int USER = 0;
3736
public static final int PASS = 1;
3837
public static final int ACCT = 2;
@@ -70,6 +69,7 @@ public final class FTPCommand
7069
public static final int MDTM = 33;
7170
/** @since 2.1 */
7271
public static final int FEAT = 34;
72+
public static final int MFMT = 35;
7373

7474
public static final int USERNAME = USER;
7575
public static final int PASSWORD = PASS;
@@ -105,9 +105,10 @@ public final class FTPCommand
105105
//public static final int HELP = HELP;
106106
//public static final int NOOP = NOOP;
107107
/** @since 2.0 */
108-
public static final int MOD_TIME = MDTM;
108+
public static final int GET_MOD_TIME = MDTM;
109109
/** @since 2.1 */
110110
public static final int FEATURES = FEAT;
111+
public static final int SET_MOD_TIME = MFMT;
111112

112113
// Cannot be instantiated
113114
private FTPCommand()
@@ -117,7 +118,7 @@ private FTPCommand()
117118
"USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT",
118119
"PASV", "TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO",
119120
"REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST",
120-
"NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT"
121+
"NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT", "MFMT"
121122
};
122123

123124
/**

0 commit comments

Comments
 (0)