return;
}
}
// get filenames
FtpFile file = null;
try {
file = session.getFileSystemView().getFile(fileName);
} catch (Exception e) {
LOG.debug("File system threw exception", e);
}
if (file == null) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"APPE.invalid", fileName));
return;
}
fileName = file.getAbsolutePath();
// check file existance
if (file.doesExist() && !file.isFile()) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"APPE.invalid", fileName));
return;
}
// check permission
if (!file.isWritable()) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"APPE.permission", fileName));
return;
}
// get data connection
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_150_FILE_STATUS_OKAY, "APPE", fileName));
DataConnection dataConnection;
try {
dataConnection = session.getDataConnection().openConnection();
} catch (Exception e) {
LOG.debug("Exception when getting data input stream", e);
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "APPE",
fileName));
return;
}
// get data from client
boolean failure = false;
OutputStream os = null;
try {
// find offset
long offset = 0L;
if (file.doesExist()) {
offset = file.getSize();
}
// open streams
os = file.createOutputStream(offset);
// transfer data
long transSz = dataConnection.transferFromClient(session.getFtpletSession(), os);
// attempt to close the output stream so that errors in