最近在工作中遇到了一个问题,一直悬而未决。ftp上传文件后为什么偶尔会有文件在ftp中找不到呢,
但日志中却显示了此文件上传成功的。
public synchronized boolean uploadToFtp(String filePath, String remoteFileName)
{
try{
FTPClient f = new FTPClient();
InetAddress server = InetAddress.getByName(rc.getFtpHost());
f.connect(server, rc.getFtpPort());
f.login(rc.getFtpUser(), rc.getFtpPassword());
log.debug("Reply String: " + f.getReplyString());
f.setFileType(f.BINARY_FILE_TYPE);
f.enterLocalPassiveMode();
log.debug("Reply String: " + f.getReplyString());
InputStream is = new FileInputStream(filePath);
// InputStream is = new getNutchInputStream(filePath);
boolean retValue = f.storeFile(remoteFileName, is);
is.close();
log.debug("retValue " + retValue);
log.debug("client status " + f.getStatus());
log.debug("filenames " + Arrays.toString(f.listNames()));
f.disconnect();
log.info(filePath + " successfully uploaded");
}catch(Exception e){
log.info( "exception is -->"+e.getStackTrace());
}
return retValue;
}