当前位置: 首页 > news >正文

湘潭网站建设 排名磐石网络提供邯郸移动网站建设

湘潭网站建设 排名磐石网络,提供邯郸移动网站建设,网站浏览量提升,广州自助企业建站模板如果下载多个文件的时候#xff0c;有时候莫名其妙的出现500服务器错误#xff0c;很有可能是没有设置KeepAlive 属性导致的。 出现应用程序未处理的异常#xff1a;2015/1/6 11:40:56 异常类型#xff1a;WebException 异常消息#xff1a;远程服务器返回错误: (500) 语法… 如果下载多个文件的时候有时候莫名其妙的出现500服务器错误很有可能是没有设置KeepAlive 属性导致的。 出现应用程序未处理的异常2015/1/6 11:40:56 异常类型WebException 异常消息远程服务器返回错误: (500) 语法错误无法识别命令。 参考http://www.cnblogs.com/webabcd/archive/2007/01/21/626242.html  KeepAlive - 指定连接是应该关闭还是在请求完成之后关闭默认为true /// summary/// FTP下载文件带进度条/// /summary/// param namefilename/parampublic void DownloadFile(string filename){float percent 0;string filePathName string.Empty;string url string.Empty;filePathName Path.Combine(Application.StartupPath, filename);string dirPath GetDirPath(filePathName);if (!Directory.Exists(dirPath))Directory.CreateDirectory(dirPath);//替换文件目录中的路径为网络路径filename filename.Replace(\\, /);url ftp:// clientUpdateInfo.UpdateFTPIP / clientUpdateInfo.UpdatePath / filename;var reqFtp (FtpWebRequest)FtpWebRequest.Create(new Uri(url));reqFtp.Method WebRequestMethods.Ftp.DownloadFile;reqFtp.UseBinary true;reqFtp.KeepAlive false;//一定要设置此属性否则一次性下载多个文件的时候会出现异常。reqFtp.Credentials new NetworkCredential(clientUpdateInfo.FtpUserName, clientUpdateInfo.FtpUserPwd);var response (FtpWebResponse)reqFtp.GetResponse();long totalBytes response.ContentLength;if (prog ! null){this.BeginInvoke(new MethodInvoker(delegate(){prog.Maximum (int)totalBytes;}));}Stream st response.GetResponseStream();var so new FileStream(filePathName, FileMode.Create);long totalDownloadedByte 0;byte[] by new byte[1024];int osize st.Read(by, 0, (int)by.Length);while (osize 0){totalDownloadedByte osize totalDownloadedByte;so.Write(by, 0, osize);if (prog ! null){this.BeginInvoke(new MethodInvoker(delegate(){prog.Value (int)totalDownloadedByte;}));}osize st.Read(by, 0, (int)by.Length);percent (float)totalDownloadedByte * 1.0f / (float)totalBytes * 100;Application.DoEvents();this.BeginInvoke(new MethodInvoker(delegate(){lbDownInfo.Text 正在下载 filename ,下载进度为: Math.Round(percent, 2) %;lbDownInfo.Refresh();}));Application.DoEvents();}so.Close();st.Close();response.Close();}private void FtpDownload(string filename){string filePathName string.Empty;string url string.Empty;filePathName Path.Combine(Application.StartupPath, filename);string dirPath GetDirPath(filePathName);if (!Directory.Exists(dirPath))Directory.CreateDirectory(dirPath);//替换文件目录中的路径为网络路径filename filename.Replace(\\, /);url ftp:// clientUpdateInfo.UpdateFTPIP / clientUpdateInfo.UpdatePath / filename;FtpWebRequest reqFTP;this.BeginInvoke(new MethodInvoker(delegate(){this.lbDownInfo.Text 开始下载中...;}));FileStream outputStream new FileStream(filePathName, FileMode.Create);reqFTP (FtpWebRequest)FtpWebRequest.Create(new Uri(url));reqFTP.Credentials new NetworkCredential(clientUpdateInfo.FtpUserName, clientUpdateInfo.FtpUserPwd);reqFTP.Method WebRequestMethods.Ftp.DownloadFile;reqFTP.UseBinary true;reqFTP.KeepAlive false;FtpWebResponse response (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream response.GetResponseStream();int bufferSize 1024;int readCount;byte[] buffer new byte[bufferSize];readCount ftpStream.Read(buffer, 0, bufferSize);//FTP上文件的大小int allbye GetFtpFileSize(filename);// (int)response.ContentLength;int startbye 0;this.BeginInvoke(new MethodInvoker(delegate(){this.prog.Maximum allbye;this.prog.Minimum 0;this.prog.Visible true;this.lbDownInfo.Visible true;}));while (readCount 0){outputStream.Write(buffer, 0, readCount);readCount ftpStream.Read(buffer, 0, bufferSize);startbye readCount;this.BeginInvoke(new MethodInvoker(delegate(){this.lbDownInfo.Text 已下载: (int)(startbye / 1024) KB/ 总长度: (int)(allbye / 1024) KB 文件名: filename;prog.Value startbye;this.lbDownInfo.Refresh();}));Application.DoEvents();Thread.Sleep(5);}this.BeginInvoke(new MethodInvoker(delegate(){this.prog.Visible false;this.lbDownInfo.Text 下载成功!;}));ftpStream.Close();outputStream.Close();response.Close();}
http://www.sadfv.cn/news/137618/

相关文章:

  • php网站做退出的代码西安观止软件科技有限公司
  • 改进网站建设做网站的qq兼职
  • 深圳网站设计公司如何网站常用字号
  • 建设网站如何加入搜索修改wordpress首页header
  • 做网站挣钱来个好心人指点一下呗常州网站建设解决方案
  • 安徽省住房和城乡建设厅网站领域铁岭开原网站建设
  • 网站需求列表高邮网站开发
  • 东莞凤岗做网站商标设计logo图案需要注册吗
  • 网站优化定做精神文明建设网站
  • 北京做网站开发公司金蝶库存管理软件
  • 公司网站市场价网站建设与管理案例教程在线阅读
  • php网站进后台wordpress无需代码建站
  • 四川自助网站使用最佳搜索引擎优化工具
  • 网站带数据库下载做电影网站的程序
  • 自己做的网站有什么用网站建设价钱
  • 郑州网站改版网站联系我们的地图怎么做
  • 网站源码建站教程wordpress 插件表单 写入数据库
  • 建设一个网站需要条件威县做网站哪里便宜
  • 建立企业网站选什么好建设银行网站无法打开
  • 什么是个人网站做图片推广的网站吗
  • 网站页面是自己做还是使用模板上海百度公司
  • 直播网站 建设上海网站建设公司排行
  • 旅游网站设计图片金湖建设局网站
  • 做ppt的模板网站链接搜索引擎
  • 厦门网站开发排名工业设计官网
  • 桂林北站附近住宿杭州学网站建设
  • 沈阳网站制作机构湖南响应式官网建设哪里有
  • 建网站服务器用哪种网站建设策划师
  • 小企业网站建设地点无限流量网站建设
  • 品牌高端网站设计怎么在wordpress建站