0

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. Running the Script and downloading the File via Renci.SshNet works flawlessly. 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?). I copy and pasted the Code directly from here (Simple full extract from a TGZ (.tar.gz)) and edited it for my Needs:

        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. 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). - string = @"C:..\logs", string = "C:\..\logs", string = @"C:..\logs\", etc. - tried it without myTime - using ICSharpCode.SharpZipLib.Core;

I did a MessageBox.Show(localDir); before the tarArchive.ExtractContents(localDir); and it showed "C:\Users\Baumann\Desktop\logs20140530" which is correct, thats the Directory I want to extract it to. 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).

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.

Thanks in advance.

  • You've got a lot going on here; try making the problem smaller. Create a .tgz (or .zip or some other kind of file), place it on your desktop, then hard-code the path in the program. This is for several reasons. 1. It's an important part of the etiquette on this site. 2. It's important to try and solve one problem at a time -- and this is even more important if you're just starting out. – David May 30 '14 at 12:06
  • Hi David, thank you. I created a new Project, placed logs.tgz on my Desktop (C:\Users\Baumann\Desktop") and tried to extract it to "C:\..\Desktop\logs". But the same Problem occurs... – Pascal Baumann May 30 '14 at 12:09
  • I would also start with a very simple archive -- say one file (inside the .tar). Then try several files, then add subdirectories, then nested subdirectories, etc. – David May 30 '14 at 12:22
  • You should also post the exception details (also for the `InnerException' if there is one). – David May 30 '14 at 12:23
  • Hi David, I tested now what you said and what I found out is when I open the .tgz with 7zip, copy the files for example in the Folder "temp", delete all the files in the .tar, save it, reopen it and copy the files all back in and then saving it again, I am able to untar it without any Errors. I tried executing my Program as Administrator, but that didn't help either... – Pascal Baumann May 30 '14 at 13:43
  • If I'm understanding you correctly, you don't get the error if you create the tar archive on Windows, only when you download it from the Linux machine. If so, that sounds like a tar format incompatibility. Try removing compression from the mix () and see if that helps. You might also try a different version (implementation) of tar on the Linux box if that's an option. – David May 30 '14 at 13:50
  • Yes, I'm not really creating a new one. I'm deleting the files, saving it, adding the files back in and saving it again. Thats not an option for me, sorry... I have to work with what the Linux Machine provides me. I started looking for some 7zip Libraries and Saw SevenZipSharp, but I have to add the 7z.dll and that gives me an Error that its not a valid Assembly or COM-Component. – Pascal Baumann May 30 '14 at 14:08

1 Answers1

0

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. I am now extracting file by file and checking each file for ":" and replacing it with "_", works flawlessly.