其实需求是这样,

要做一键导出,

有图片,有照片,youhtml,存在不同的文件夹,每次下载都必须下载最新数据,因为FTP是随时更新的。

1.这要是一直下载下载,浏览器一直跳窗口,蛋疼的我都看不下去。所以,只能选择别的办法

2.要是放在WEB下载,我觉得肯定会崩溃的呀,所以想选择客户端直接下载,但是必须得装插件,类型ActionX之类的。头给否认了。我凑,只能想别的办法

3.只能先用WEB把流读下来,压缩,然后传给用户,很蛋疼,这要是谁点了,多考验服务器内存CPU,但是头说了,这样也比插件好,好吧,开始做吧

学习连接

http://www.csharpwin.com/dotnetspace/7579r311.shtml

下面是代码

     #region Zip multi files

        public static int Zip(string destFolder, string[] srcFiles, string folderName, CompressLevel level)
{
OperFileFTP operFileFTP = new OperFileFTP(); ZipOutputStream zipStream = null; int count = ; string snappath = "ftp://ip"; try
{ //Use Crc32
Crc32 crc32 = new Crc32(); Stream ftpoutStream = null; //Create Zip File
zipStream = new ZipOutputStream(File.Create(destFolder)); //Specify Level
zipStream.SetLevel(Convert.ToInt32(level)); #region Foreach File;
foreach (string file in srcFiles)
{
Uri u;
if (file != null)
{
string filepath = file;
string ftpfilepath = file;
if (Path.GetExtension(file) == ".jpg")
{
u = new Uri(snappath);
filepath = filepath.Replace("\\", "/");
ftpfilepath = ftpfilepath.Replace("\\", "/");
} else
{
u = new Uri(ftppath);
}
filepath = filepath.Substring(, filepath.LastIndexOf("/")); clsFTP cs = new clsFTP(u, entity.User_Name, entity.Pwd); byte[] buffer = cs.DownloadFile(ftpfilepath); //Specify ZipEntry
crc32.Reset();
crc32.Update(buffer);
ZipEntry zipEntry = new ZipEntry(Path.Combine(filepath, Path.GetFileName(file)));
zipEntry.DateTime = DateTime.Now;
zipEntry.Size = buffer.Length;
zipEntry.Crc = crc32.Value; //Put file info into zip stream
zipStream.PutNextEntry(zipEntry); zipStream.Write(buffer, , buffer.Length); count++;
}
} if (!string.IsNullOrEmpty(folderName))
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(folderName); //Specify ZipEntry
crc32.Reset();
crc32.Update(buffer);
ZipEntry zipEntry = new ZipEntry(Path.Combine("", Path.GetFileName("OperationReport.htm")));
zipEntry.DateTime = DateTime.Now;
zipEntry.Size = buffer.Length;
zipEntry.Crc = crc32.Value; //Put file info into zip stream
zipStream.PutNextEntry(zipEntry); //Put file data into zip stream
zipStream.Write(buffer, , buffer.Length); count++;
}
#endregion; if (ftpoutStream != null)
ftpoutStream.Flush();
}
catch
{
throw;
}
finally
{
//Clear Resource if (zipStream != null)
{
zipStream.Finish();
zipStream.Close();
}
}
FileStream stream = new FileStream(destFolder, FileMode.Open);
//long cl = stream.ContentLength; HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(Path.GetFileName(destFolder))); int bufferSize = ; int readCount; byte[] bufferr = new byte[bufferSize]; char[] cChar = Encoding.ASCII.GetChars(bufferr);
//接收FTP文件流 while ((readCount = stream.Read(bufferr, , )) > )
{
HttpContext.Current.Response.OutputStream.Write(bufferr, , readCount);
HttpContext.Current.Response.Flush();
}
stream.Flush();
stream.Close(); if (File.Exists(destFolder))
File.Delete(destFolder);
return count; } #endregion

方法如上。。

一下为引用代码。。

时间有限,有机会补充

   string[] files = new string[]; 

   Zip(context.Server.MapPath("Tech_" + id + ".zip"), files, str, CompressLevel.Level8);

b/s 读取多个FTP文件(图片,视频)压缩到服务器 下载到客户端的更多相关文章

  1. smbclient - 类似FTP操作方式的访问SMB/CIFS服务器资源的客户端

    总览 SYNOPSIS smbclient {servicename} [password] [-b <buffer size>] [-d debuglevel] [-D Director ...

  2. webpack处理媒体文件(图片/视频和音频)

    webpack最终会将各个模块打包成一个文件,因此我们样式中的url路径是相对入口html页面的, 这个问题是用file-loader解决的,file-loader可以解析项目中的url引入(不仅限于 ...

  3. MVC文件图片ajax上传轻量级解决方案,使用客户端JSAjaxFileUploader插件01-单文件上传

    前段时间做了几个关于图片.文件上传的Demo,使用客户端Query-File-Upload插件和服务端Badkload组件实现多文件异步上传,比如"MVC文件上传04-使用客户端jQuery ...

  4. Java实现FTP文件与文件夹的上传和下载

    Java实现FTP文件与文件夹的上传和下载 FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议".用于Internet上的控制 ...

  5. FTP文件操作之下载文件

    前面写了采用ftp上传文件,有了上传怎么能够没有下载呢?如果只有上传没有下载,那上传了也没啥用了.所以今天就跟大家一起学习学习使用ftp下载文件. 知道了怎么上传,那么下载也就变得很简单了,上传是把文 ...

  6. C#本地文件下载以及FTP文件服务下载(以Pdf文件为例)

    一.C#实现本地文件下载 1.文件下载的路径  文件名称 以及文件下载之后要放的位置  这三个变量是必须要的 2.定义以下四个对象: FileWebRequest ftpWebRequest = nu ...

  7. 读取FTP 图片文件,并显示,非下载

    关于FTP,先从怎么创建开始说起,很简单,步骤就两个 ① 电脑-右键管理--本地用户组--添加用户名,密码(用于FTP的用户名.密码) ② IIS 新建FTP站点,命名,指定端口号.FTP文件路径 接 ...

  8. informatica读取FTP文件

    以下为一个完整的informatica读取ftp文件,并导入到系统中. 第一步: 通过shell脚本下载压缩包文件 /server/infa_shared/crm_prod/shell/ftpFrom ...

  9. 【数据下载】利用wget命令批量下载ftp文件和文件夹

    这是一个“”数据大发现”的时代,大家都在创造数据,使用数据以及分享数据,首先一步我们就需要从数据库download我们需要的数据. Ftp是一种常见的在线数据库,今天介绍一种可以批量下载文件夹的方法, ...

随机推荐

  1. Java 基础接口练习题

    编写2个接口:InterfaceA和InterfaceB:在接口InterfaceA中有个方法void printCapitalLetter():在接口InterfaceB中有个方法void prin ...

  2. build.gradle文件详解<转> 推荐

    apply plugin: 'com.android.application'//说明module的类型,com.android.application为程序,com.android.library为 ...

  3. MVC的多表单

    中心思想就是在一个表单内不规定"action",在js里面用@Url.Axtion("视图层","控制器")方法来设置表单的传值. 控制器 ...

  4. python 中的decorator

    python 中decorator的作用就是一个包装的作用,所谓包装指在执行真正的函数之前或者之后,我们可以有一些额外的发挥余地. decorator形式如下 def dec(arg1): print ...

  5. window7 x64 path

    %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem; %SYSTEMROOT%\System32\WindowsPowerS ...

  6. VS2013 带命令行参数的调试问题 解决方案

    int main(int argc,char* argv[]) argc是命令行总的参数个数,argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数命令行后面跟的用户输入的参数 比如:  ...

  7. 广度优先搜索(BFS)

    定义 维基百科:https://en.wikipedia.org/wiki/Breadth-first_search 给定图G=(V,E)和一个可识别的源结点s,广度优先搜索对图G中的边进行系统性的探 ...

  8. django_cms安装技巧

    首先python的版本要高一些,否则安装django-cms会报错 安装cmsinstaller不能够正常下载 利用virtualenv进行安装配置 注意中文的配置 djangocms配置中文 dja ...

  9. MongoDB 概念解析

    SQL术语/概念 MongoDB术语/概念 解释/说明 database database 数据库 table collection 数据库表/集合 row document 数据记录行/文档 col ...

  10. goroutine

    Go语言从诞生到普及已经三年了,先行者大都是Web开发的背景,也有了一些普及型的书籍,可系统开发背景的人在学习这些书籍的时候,总有语焉不详的感觉,网上也有若干流传甚广的文章,可其中或多或少总有些与事实 ...