压缩许多文件并将其上传到FTP

本文关键字:FTP 许多 文件 压缩 | 更新日期: 2023-09-27 18:28:21

我需要将多个图像文件上传到FTP。

这里要实现的主要目标是性能和速度

我在这里的方法是,在客户端压缩所有文件,并通过ftp上传它们,然后将它们重新归档到服务器上。

有更好的方法吗??

最好的压缩方式是什么?我应该使用.net内置机制还是一些外部库?

注:我有VS 2012的开发环境。

压缩许多文件并将其上传到FTP

Zip it on the client结束并FTP it和unzip them on the server将是性能和速度方面的最佳方法。向服务器发送1000多个文件将不是一个理想的解决方案。

最好使用开源库来压缩文件。您可以使用Ionic Zip。您可以使用公开的API轻松地压缩和解压文件。

代码示例

压缩文件

 using (ZipFile zip = new ZipFile())
 {
     // add this map file into the "images" directory in the zip archive
     zip.AddFile("c:''images''personal''7440-N49th.png", "images");
     zip.Save("MyZipFile.zip");
 }

解压缩文件

    public void ExtractZipFile(string fullZipFileName, string extractPath)
    {
        using (ZipFile zip = ZipFile.Read(fullZipFileName))
        {
            //Extract the zip file
            zip.ExtractAll(extractPath);
        };
    }