日期:2014-05-20  浏览次数:20648 次

如何获取上传到ftp服务端的文件大小
请问一下,把文件上传到ftp服务端后,我想获取到这个文件上传到服务端的大小,来比较原来的大小,判断文件是否上传成功。我在文件上传完后,
客户端:

TelnetOutputStream tos=ftpClient.put(FtpClientCon.upFileName);
responseInfo=FtpClientCon.ftpClient.getResponseString();
System.out.println("put返回的信息:"+responseInfo);
//打开一个输出流
DataOutputStream dos=new DataOutputStream(tos);

//循环读取文件上传数据,while((sendFile.getFilePointer()+1)<sendFile.length())
while((dataLength=sendFile.read(b))!=-1)
{
dos.write(b,0,dataLength);//把数据写入输出流
dos.flush();
}
String responseInfo=FtpClientCon.ftpClient.getResponseString();
System.out.println("返回上传的文件的大小信息:"+responseInfo);

服务端:

BufferedInputStream bin=null;
RandomAccessFile receiveFile=null;
byte[] buf = new byte[2048000];
int dataLength = 0;
try
{
out.println("150 Opening Binary mode data connection for "+ requestfile);

dsocket = new Socket(remoteHost,remotePort,InetAddress.getLocalHost(),20);

bin = new BufferedInputStream(dsocket.getInputStream());

while((dataLength = bin.read(buf))!=-1)
{
receiveFile.write(buf,0,dataLength);//写入文件
}//while()
   
//返回给发送方的信息
out.println("receive the "+param+" file's size is "+upfile.length());
}
但是取到的都是150 Opening Binary mode data connection for "+ requestfile,没有文件的大小返回。


希望各位高手能够帮帮忙!


------解决方案--------------------
写一个读取文件大小的的程序就可以了。
------解决方案--------------------
上传前 先得到文件的大小
传给服务器
服务器得到上传文件后
比较大小 就知道是不是传完整了
------解决方案--------------------
本地不就可以得到了