最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net文件断点续传代码
时间:2022-06-25 05:35:38 编辑:袖梨 来源:一聚教程网
asp教程.net文件断点续传代码
ftpwebrequest ftprequest = (ftpwebrequest)webrequest.create(_uri);
ftprequest.method = webrequestmethods.ftp.downloadfile;
ftprequest.keepalive = false;
ftprequest.usebinary = true;
ftprequest.contentoffset = segment.begin;
ftprequest.credentials = new networkcredential(_username, _password);
using (ftpwebresponse ftpresponse = (ftpwebresponse)ftprequest.getresponse())
using (filestream file = new filestream(savetemppath, filemode.open, fileaccess.write, fileshare.write))
using (stream responsestream = ftpresponse.getresponsestream())
{
file.seek(segment.begin, seekorigin.begin);
int poswrite = segment.begin;
byte[] buf = new byte[_bufsize];
int readbytes = 0;
while (!responsestream.canread)
{
thread.sleep(0);
}
while ((readbytes = responsestream.read(buf, 0, buf.length)) > 0)
{
int byteslack = segment.end - poswrite + 1;
if (readbytes > byteslack)
{
file.write(buf, 0, byteslack);
poswrite += byteslack;
}
else
{
file.write(buf, 0, buf.length);
poswrite += buf.length;
}file.flush();
segment.begin = poswrite;
// todo: save segmentif (poswrite > segment.end)
{
break;
}
while (!responsestream.canread)
{
thread.sleep(0);
}
}
responsestream.close();
file.close();
ftpresponse.close();
//注明必须置contentoffset
相关文章
- 时空中的绘旅人天宇之间怎么玩 绘旅人天宇之间活动玩法介绍 12-25
- QQ2024年度报告怎么看 2024qq年度报告玩法介绍 12-25
- 归龙潮珠砂什么时候up 归龙潮红缘绮梦卡池介绍 12-25
- 王者荣耀S38赛季有什么更新 12-25
- 王者荣耀S38赛季有什么更新 王者荣耀S38赛季更新内容介绍 12-25
- 世界之外12.25有什么更新 世界之外12月25日更新内容介绍 12-25