返回信息流文件的原始大小是18618521 ,传到ftp服务器后的文件大小只有16894722了。
我的代码是:
Java code
/**
* do with the command doRETR
* @return state boolean if there is a exception or true
*/
private boolean doSTOR(String path)
{
boolean stat = true;
Socket dataSock = null;
BufferedReader dataReader = null;
BufferedWriter datawriter = null;
try
{
//pasv Mode 被动模式 服务器建立监听socket(在pasv命令中建立) 等待client连接
if(this.pasvSocket != null)
dataSock = this.pasvSocket.accept();
//active mode 主动模式 客户端建立好了监听socket 服务器去连接客户端
else
dataSock = new Socket(this.ip,this.port);
datawriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path)));
dataReader = new BufferedReader(new InputStreamReader(dataSock.getInputStream()));
//这里是上传文件的代码
this.response("150 Opening ASCII mode data connection.");
char [] buf = new char[4096*8];
int length = 0;
while((length = dataReader.read(buf)) !=-1 )
{
datawriter.write(buf,0,length);
datawriter.flush();
}
this.response("226 transfer complete.");
}
catch (UnknownHostException e)
{
AFtpLogger.getInstance().log(e.getMessage());
e.printStackTrace();
return false;
}
catch (IOException e)
{
AFtpLogger.getInstance().log(e.getMessage());
e.printStackTrace();
this.response("550 No such file or directory");
return false;
}
finally //release the resource;
{
try
{
if(dataSock != null) dataSock.close();
if(pasvSocket != null) pasvSocket.close();
if(datawriter != null) datawriter.close();
if(dataReader != null) dataReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return stat;
}
这是一条镜像帖。来源:北邮人论坛 / java / #19187同步于 2011/7/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
求高手指点:自己用socket做了一个ftp服务器 上传和下载文件不
buptjunjun
2011/7/3镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
猜测是IO流的问题
【 在 buptjunjun (CrazySinger) 的大作中提到: 】
: [upload=1][/upload]
: 文件的原始大小是18618521 ,传到ftp服务器后的文件大小只有16894722了。
: 我的代码是:
: ...................
谢谢 问题已经解决了。
【 在 buptlong 的大作中提到: 】
: 猜测是IO流的问题
: 【 在 buptjunjun (CrazySinger) 的大作中提到: 】
: : [upload=1][/upload]
: ...................