DataConnectionFactory connFactory = session.getDataConnection();
if (connFactory instanceof IODataConnectionFactory) {
InetAddress address = ((IODataConnectionFactory) connFactory)
.getInetAddress();
if (address == null) {
session.write(new DefaultFtpReply(
FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
return;
}
}
// reset state variables
session.resetState();
String pathName = request.getArgument();
// get filenames
FtpFile file = null;
try {
String filePrefix;
if (pathName == null) {
filePrefix = "ftp.dat";
} else {
FtpFile dir = session.getFileSystemView().getFile(
pathName);
if (dir.isDirectory()) {
filePrefix = pathName + "/ftp.dat";
} else {
filePrefix = pathName;
}
}
file = session.getFileSystemView().getFile(filePrefix);
if (file != null) {
file = getUniqueFile(session, file);
}
} catch (Exception ex) {
LOG.debug("Exception getting file object", ex);
}
if (file == null) {
session.write(LocalizedDataTransferFtpReply.translate(session, request, context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOU",
null, null));
return;
}
String fileName = file.getAbsolutePath();
// check permission
if (!file.isWritable()) {
session.write(LocalizedDataTransferFtpReply.translate(session, request, context,
FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"STOU.permission", fileName, file));
return;
}
// get data connection
session.write(new DefaultFtpReply(
FtpReply.REPLY_150_FILE_STATUS_OKAY, "FILE: " + fileName));
// get data from client
boolean failure = false;
OutputStream os = null;