文件传输时传输的文件小于实际大小 [英] when file transfer it is transfer less than actual size

查看:123
本文介绍了文件传输时传输的文件小于实际大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将文件从客户端传输到服务器或还原到文件传输小于文件实际大小时,我正在执行c#中的全局回收站项目,为什么会发生这种情况?

i am doing project of global recycle bin in c#when i am transfer file from client to server or restoring it file transfer less than actual size of file why this happend? what should i do to handle this?

推荐答案

您可能会发现,这是由于协议(可能是ftp或不太可能的tcp)将文件传输拆分为数据包造成的.如果遇到这种情况,您的代码可能需要从流中读取(我想您正在使用)以传输到文件,以实际从流中读取整个文件.类似于以下内容的循环:

You may find this is due to the protocol (possibly ftp or less likely tcp) splitting the file transfer into packets. If this coccured your code may need to read from the stream (that I presume you are using) to transfer to the file to actually read the entire file from the stream. A loop similar to:

int BytesRead = Stream.Read(...);
while(BytesRead > 0)
{
BytesRead = Stream.Read(...);
}



那么在Stream.Read方法中用作缓冲区的任何内容都将包含所有文件字节,而不仅仅是其中一些字节.一个很好的检查方法就是检查缓冲区是否包含预期的字节数.



then whatever you use as your buffer in the Stream.Read method will contain all the file bytes rather than just some of them. A good check is also to check if your buffer contains the number of bytes you expected.


这篇关于文件传输时传输的文件小于实际大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆