in core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java [52:163]
public void execute(final FtpIoSession session,
final FtpServerContext context, final FtpRequest request)
throws IOException {
// reset state variables
session.resetState();
String argument = request.getArgument();
if (argument == null || argument.trim().length() == 0) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"MFMT.invalid", null));
return;
}
String[] arguments = argument.split(" ",2);
if(arguments.length != 2) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"MFMT.invalid", null));
return;
}
String timestamp = arguments[0].trim();
try {
Date time = DateUtils.parseFTPDate(timestamp);
String fileName = arguments[1].trim();
// get file object
FtpFile file = null;
try {
file = session.getFileSystemView().getFile(fileName);
} catch (Exception ex) {
LOG.debug("Exception getting the file object: " + fileName, ex);
}
if (file == null || !file.doesExist()) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"MFMT.filemissing", fileName));
return;
}
// check file
if (!file.isFile()) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"MFMT.invalid", null));
return;
}
// check if we can set date and retrieve the actual date stored for the file.
if (!file.setLastModified(time.getTime())) {
// we couldn't set the date, possibly the file was locked
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "MFMT",
fileName));
return;
}
// all checks okay, lets go
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_213_FILE_STATUS,
"MFMT", "ModifyTime=" + timestamp + "; " + fileName));
return;
} catch (ParseException e) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"MFMT.invalid", null));
return;
}
}