session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_150_FILE_STATUS_OKAY, "RETR", null));
// send file data to client
boolean failure = false;
InputStream is = null;
DataConnection dataConnection;
try {
dataConnection = session.getDataConnection().openConnection();
} catch (Exception e) {
LOG.debug("Exception getting the output data stream", e);
session.write(LocalizedDataTransferFtpReply.translate(session, request, context,
FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "RETR",
null, file));
return;
}
long transSz = 0L;
try {
// open streams
is = openInputStream(session, file, skipLen);
// transfer data
transSz = dataConnection.transferToClient(session.getFtpletSession(), is);
// attempt to close the input stream so that errors in
// closing it will return an error to the client (FTPSERVER-119)
if(is != null) {
is.close();
}
LOG.info("File downloaded {}", fileName);
// notify the statistics component