"RNTO", null));
return;
}
// get the "rename from" file object
FtpFile frFile = session.getRenameFrom();
if (frFile == null) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "RNTO",
null));
return;
}
// get target file
FtpFile toFile = null;
try {
toFile = session.getFileSystemView().getFile(toFileStr);
} catch (Exception ex) {
LOG.debug("Exception getting file object", ex);
}
if (toFile == null) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
"RNTO.invalid", null));
return;
}
toFileStr = toFile.getAbsolutePath();
// check permission
if (!toFile.isWritable()) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
"RNTO.permission", null));
return;
}
// check file existance
if (!frFile.doesExist()) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
"RNTO.missing", null));
return;
}
// save away the old path
String logFrFileAbsolutePath = frFile.getAbsolutePath();
// now rename
if (frFile.move(toFile)) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "RNTO",
toFileStr));
LOG.info("File rename from \"{}\" to \"{}\"", logFrFileAbsolutePath,
toFile.getAbsolutePath());
} else {
session
.write(LocalizedFtpReply
.translate(
session,