当前位置: 代码迷 >> ASP.NET >> 小弟我想从服务器向客户端一次性推送多个文件,请教应该如何做
  详细解决方案

小弟我想从服务器向客户端一次性推送多个文件,请教应该如何做

热度:1292   发布时间:2013-02-25 00:00:00.0
我想从服务器向客户端一次性推送多个文件,请问应该怎么做?
服务器上每个月都会生成几十甚至上百个文件,都在同一个目录下,客户想单击一下按钮后一次性下载多个文件到本地,而不用一个一个的下载,请问能够实现吗?

------解决方案--------------------------------------------------------
/// <summary>
/// 从台服务器获取文件到本地
/// </summary>
private void DoDownFile(string HttpString, string Table, string SerialNo)
{
//http路径加文件名
HttpString += Table + ".txt ";
try
{
HttpWebRequest Request = (HttpWebRequest) HttpWebRequest.Create(HttpString);
Request.Headers.Add( "Translate: f ");
Request.Credentials = CredentialCache.DefaultCredentials;

HttpWebResponse Response = (HttpWebResponse) Request.GetResponse();
//日志
fun.log(null,HttpString+ " DownLoad OK ");

Stream respStream = null;
respStream = Response.GetResponseStream();
int FileSize = int.Parse(Response.ContentLength.ToString());

byte[] buffer = new byte[FileSize];
//写到本地
String dir = GetSaveDisk + SerialNo + "\\ " + Str.NowShort + "\\ ";
Directory.CreateDirectory(dir);
String dpath = dir + Table + ".txt ";
FileStream fs = File.Open(dpath, FileMode.Create, FileAccess.Write);
int length;
length = respStream.Read(buffer, 0, FileSize);
long writeLength = length;
while (length != 0)
{
fs.Write(buffer, 0, length);
length = respStream.Read(buffer, 0, FileSize);
writeLength += (long) length;
}
fs.Close();
}
catch (Exception e)
{
DownLoadError+=1;
//错误日志
fun.log(e,HttpString+ " DownLoad FAILED ");
}
}
  相关解决方案