简体   繁体   English

C#SharpZipLib提取.TGZ NotSupportedException

[英]C# SharpZipLib extract .TGZ NotSupportedException

I'm new to programming so please be patient. 我是编程新手,所以请耐心等待。

I am currently developing a small Program in Visual C# 2010 Express, .NET Framework 4.0, which starts a Script on a Linux Machine (what creates the File /tmp/logs.tgz), downloads the File and then I want to extract it. 我目前正在Visual C#2010 Express,.NET Framework 4.0中开发一个小程序,该程序可在Linux机器上启动脚本(由其创建文件/tmp/logs.tgz),下载文件,然后提取该文件。 Running the Script and downloading the File via Renci.SshNet works flawlessly. 运行脚本并通过Renci.SshNet下载文件可完美运行。 But when I want to extract it, it gives me an Error "NotSupportedException" my Filepath Format is incorrect (which is not the case, I think?). 但是,当我要提取它时,它给我一个错误“ NotSupportedException”,我的文件路径格式不正确(我认为不是这种情况)。 I copy and pasted the Code directly from here (Simple full extract from a TGZ (.tar.gz)) and edited it for my Needs: 我直接从此处复制并粘贴代码(从TGZ(.tar.gz)提取完整内容),并根据需要对其进行了编辑:

        using System.IO;
        using System.IO.Compression;
        using ICSharpCode.SharpZipLib.GZip;
        using ICSharpCode.SharpZipLib.Tar;
        //it executed the Script and created the file on the Linux Machine /tmp/logs.tgz
        //now I want to download it

        string myTime = DateTime.Now.ToString("yyyyMMdd");
        var pathWithEnv = (@"%USERPROFILE%\Desktop\logs" + myTime + ".tgz");
        var filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);
        string localFile = filePath;

        //then downloads /tmp/logs.tgz to ..\Desktop\logs+ myTime +.tgz
        //everything great until now. here I want to extract .TGZ:

        var pathWithEnv2 = (@"%USERPROFILE%\Desktop\logs" + myTime);
        var fileDir = Environment.ExpandEnvironmentVariables(pathWithEnv2);
        string localDir = fileDir;

        Stream inStream = File.OpenRead(localFile);
        Stream gzipStream = new GZipInputStream(inStream);

        TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
        //ERROR OCCURS HERE:
        tarArchive.ExtractContents(localDir);

        tarArchive.Close();
        gzipStream.Close();
        inStream.Close();

I even tried to set the localFile and localDir string without the EnviromentVariable, but that didnt help. 我什至尝试在没有EnviromentVariable的情况下设置localFile和localDir字符串,但这没有帮助。 I tried: - download and extract it directly on C:\\ (or on a mapped Network Drive U:) to prevent too long filenames (which should not be the case as it should never get longer than 86 characters). 我尝试了以下操作:-直接在C:\\(或在映射的网络驱动器U :)上下载并解压缩,以防止文件名过长(不应该这样,因为它永远不能超过86个字符)。 - string = @"C:..\\logs", string = "C:\\..\\logs", string = @"C:..\\logs\\", etc. - tried it without myTime - using ICSharpCode.SharpZipLib.Core; -字符串= @“ C:.. \\ logs”,字符串=“ C:\\ .. \\ logs”,字符串= @“ C:.. \\ logs \\”,等等-在没有myTime的情况下进行了尝试-使用ICSharpCode.SharpZipLib 。核心;

I did a MessageBox.Show(localDir); 我做了一个MessageBox.Show(localDir); before the tarArchive.ExtractContents(localDir); 在tarArchive.ExtractContents(localDir)之前; and it showed "C:\\Users\\Baumann\\Desktop\\logs20140530" which is correct, thats the Directory I want to extract it to. 并显示“ C:\\ Users \\ Baumann \\ Desktop \\ logs20140530”,这是正确的,这就是我要将其提取到的目录。 Even creating the Directory before executing it doesn't help. 即使在执行目录之前创建目录也无济于事。

I also created a new Project with just one button which should start the Extraction and the same error occurs. 我还创建了一个只有一个按钮的新项目,该按钮应该开始提取,并且发生相同的错误。

I tried, doing it separately, first extract the GZip and then the .tar, but it also gives me the same Error when extracting the GZip (using ICSharpCode.SharpZipLib.Core; of course). 我尝试过单独进行操作,首先提取GZip,然后提取.tar,但是提取GZip时,它也给了我同样的错误(当然是使用ICSharpCode.SharpZipLib.Core;)。

What drives me even more crazy about it, is, that it starts to extract it, but not everything, before it fails. 使我更加疯狂的是,它在失败之前就开始提取它,但不是全部。 And always the same Files, whats not clear for me why these and why not the others. 而且总是相同的文件,对于我来说,为什么这些以及为什么其他不是,我不清楚。

I'm on Windows 8.1, using SharpZipLib 0.86.0.518, downloaded directly from the Website. 我在Windows 8.1上,使用SharpZipLib 0.86.0.518,可直接从网站下载。

Thanks in advance. 提前致谢。

well, I finally fixed the Problem. 好吧,我终于解决了问题。 The Linux machine is creating a file which includes the MAC-Adress and since Windows can't handle ":" in a Filename, it crashes. Linux机器正在创建一个包含MAC地址的文件,并且由于Windows无法处理文件名中的“:”,因此它将崩溃。 I am now extracting file by file and checking each file for ":" and replacing it with "_", works flawlessly. 我现在按文件提取文件并检查每个文件中的“:”,然后将其替换为“ _”,这一切都可以正常进行。

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

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