简体   繁体   English

从受密码保护的Zip文件中提取

[英]Extract from password protected Zip files

This is my requirement, I need to extract files from password protected zipped files. 这是我的要求,我需要从受密码保护的压缩文件中提取文件。 I would like to know if there are any code snippets available. 我想知道是否有可用的代码段。 I am using SSIS to download these zipped files from an FTP. 我正在使用SSIS从FTP下载这些压缩文件。 Is there any latest update to the 4.5 framework which I can make use of. 我可以使用4.5框架的任何最新更新吗?

Update: 更新:

I have now referenced the file and tried out an example but now I am getting an exception, I even tried to add a breakpoint in my script task but still what I get is only an exception. 我现在已经引用了该文件并尝试了一个示例,但是现在我遇到了异常,我什至尝试在脚本任务中添加断点,但是仍然得到的只是异常。

Exception: 例外:

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

Snapshot: 快照: 在此处输入图片说明

Code: 码:

try
    {
            string zipfilePath = @"C:\ZipFiles";
            string zipPassword = "qwerty";
        using (ZipFile zip = new ZipFile())
        {
            zip.Password = zipPassword;
            zip.AddFile("File-01.txt");
            zip.AddFile("File-02.txt");
            zip.AddFile("File-03.txt");
            zip.AddFile("File-04.txt");
            zip.Save(zipfilePath + "AllFiles.zip");
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.ToString());
    }

PS: I am new to C# PS:我是C#新手

DotNetZip supports password protection. DotNetZip支持密码保护。 It's available as a NuGet package and allows you to extract from a password protected zip file as follows (taken and modified from the link): 它以NuGet软件包的形式提供,允许您按如下方式从受密码保护的zip文件中提取(从链接中获取和修改):

string baseDirectory = "C:\\output";
string password = "password";

using (ZipFile zip = ZipFile.Read("MyArchive.zip"))
{
    ZipEntry e = zip["MyFile.txt"];
    e.ExtractWithPassword(baseDirectory, password);
}

There are lots of other "code-snippets" like this on the C# examples page I linked you. 我链接过的C#示例页面上还有许多其他这样的“代码片段”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM