FTP上传后,文件大小问题
"fileSize":348378,"percent":100,"sendSize":348378,"sendTimeMillis":422,"sfname":"0228jqueryeasyui.rar","sip":"本地路径","spassword":"","spath":"D:\\ftptest\\","speed":"803K","sport":21,"spwd":"*******","startTime":1352877744828,"status":"传输完成","suser":"","tfname":"0228jqueryeasyui.rar","tip":"127.0.0.1","tpassword":"","tpath":"/ftptest/","tport":21,"tpwd":"*******","tuser":""
文件大小348378,实际传输348378,完成后,服务器文件大小349,643 字节
求助。
------最佳解决方案--------------------ftpClient对象,设置以二进制传输
sender.getFtpclient().setFileType(FTPClient.BINARY_FILE_TYPE);
------其他解决方案--------------------放代码。。。
------其他解决方案--------------------代码:
InputStream in = getter.getInputStream(sif.getSfname());
OutputStream out = sender.getOutputStream(sif.getTfname());
int len = -1;
try {
psf.AddIsRunNum();
while ((len = in.read(b)) > -1)
{
if(!psf.isRun())
{
psf.AddIsInterrupt();
sif.setStatus("传输中断");
return;
}
out.write(b, 0, len);
sif.setSpeed(len);
}
logger.info("文件传输成功!"+JSON.toString(sif, false));
psf.AddIsSucessNumm();
} catch (Exception e) {
logger.error("文件传输失败!"+JSON.toString(sif, false));
psf.AddIsFailedNum();
sif.setStatus("传输失败");
e.printStackTrace();
}
finally
{
------其他解决方案--------------------finally
{
psf.minusIsRunNum();
try {
if(in!=null)
in.close();
if(getter.getFtpclient()!=null)
getter.getFtpclient().completePendingCommand();
} catch (
IOException e) {
}
try {
if(out!=null)
out.close();
if(sender.getFtpclient()!=null)
sender.getFtpclient().completePendingCommand();
} catch (IOException e) {
}
}
------其他解决方案--------------------ftpclient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpclient.login(sf.getUser(), sf.getPassword());
改为
ftpclient.login(sf.getUser(), sf.getPassword());
ftpclient.setFileType(FTPClient.BINARY_FILE_TYPE);
就可以了...