问题描述
FtpClientappendFile方法丢数据常用时间通过FtpClientappendFile方法上传数据到服务器后,发现有丢数据问题。方法如下,请大家给看看,非常感激:/***initSession**@return*@throwsIOException*/publicsynchronizedbooleaninitSession()throwsIOException{logger.info("FtpinitSession,hostname:"+hostname+",port:"+port+",username:"+username+",status:"+status);if(this.status==0){logger.debug("Status:0,neednotinitsessionrightrow.");returnfalse;}if(this.isConnected()){returntrue;}if(this.threadFtpMaintain==null){this.initFtpMaintain();}try{if(port>0){this.ftp.connect(hostname,port);}else{this.ftp.connect(hostname);}ftp.setBufferSize(10*1024);ftp.setSoTimeout(60*1000);ftp.setDataTimeout(60*1000);//ftp.setDefaultTimeout(10*1000);ftp.setKeepAlive(true);logger.info("Ftpconnectsucceed.hostname:"+hostname+",port:"+port);}catch(UnknownHostExceptionuhex){logger.error("Ftpconnectfailed.hostname:"+hostname+",port:"+port,uhex);throwuhex;}catch(IOExceptionioex){logger.error("Ftpconnectfailed.hostname:"+hostname+",port:"+port,ioex);throwioex;}finally{}StringreplyString=null;try{logger.debug("Ftplogin,username:"+username);this.ftp.user(username);replyString=this.ftp.getReplyString();logger.debug("Ftplogin,password:"+password);this.ftp.pass(password);replyString=this.ftp.getReplyString();if(FTPReply.isPositiveCompletion(this.ftp.getReplyCode())){this.ftp.syst();this.ftp.setFileType(FTPClient.BINARY_FILE_TYPE);//this.ftp.enterLocalPassiveMode();this.connected=true;logger.debug("Ftploginsucceed,hostname:"+hostname+",port:"+port+",username:"+username+",status:"+status+",isConnected:"+isConnected());returntrue;}else{this.connected=false;logger.warn("Ftploginfailed,replyString:"+replyString);returnfalse;}}catch(IOExceptionex){this.connected=false;logger.error("Ftploginfailed,username:"+username+",password:"+password,ex);throwex;}finally{replyString=null;}}publicsynchronizedbooleanappendFile(StringremoteFile,Stringcontent)throwsIOException{lock=Calendar.getInstance().getTimeInMillis();logger.debug("FtpappendFile,remoteFile:"+remoteFile+",content:"+content);StringreplyString=null;intreplyCode=-99;InputStreaminputStream=null;try{inputStream=newByteArrayInputStream(content.getBytes());this.ftp.appendFile(remoteFile,inputStream);replyString=this.ftp.getReplyString();replyCode=this.ftp.getReplyCode();if(FTPReply.isNegativeTransient(replyCode)||FTPReply.isNegativePermanent(replyCode)){logger.warn("FtpappendFilefailed,remoteFile:"+remoteFile+",content:"+content+",replyString:"+replyString);returnfalse;}else{logger.debug("FtpappendFilesucceed,remoteFile:"+remoteFile+",content:"+content+",replyString:"+replyString);returntrue;}}catch(IOExceptione1){//TODOAuto-generatedcatchblocklogger.warn("FtpappendFileContentfailed,remoteFile:"+remoteFile+",content:"+content+"n"+e1);//this.connected=false;throwe1;}finally{if(inputStream!=null){try{inputStream.close();}catch(IOExceptione){//TODOAuto-generatedcatchblocklogger.warn(e);}}replyString=null;}}
解决方案
解决方案二:
[code=c][code=java]
[/code][/code]