session.write(new DefaultFtpReply(
FtpReply.REPLY_150_FILE_STATUS_OKAY, "FILE: " + fileName));
// get data from client
boolean failure = false;
OutputStream os = null;
DataConnection dataConnection;
try {
dataConnection = session.getDataConnection().openConnection();
} catch (Exception e) {
LOG.debug("Exception getting the input data stream", e);
session.write(LocalizedDataTransferFtpReply.translate(session, request, context,
FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOU",
fileName, file));
return;
}
long transSz = 0L;
try {
// open streams
os = file.createOutputStream(0L);
// transfer data
transSz = dataConnection.transferFromClient(session.getFtpletSession(), os);
// attempt to close the output stream so that errors in
// closing it will return an error to the client (FTPSERVER-119)
if(os != null) {
os.close();
}
LOG.info("File uploaded {}", fileName);
// notify the statistics component