1

Im working with Renci SSH.Net, Is it possible to delete a file inside the ZIP file if I have the file name with me using c# .net core

1 Answers1

3

I think you can not delete a file directly in this zip file in sftp server. But you can download this zip file to a local temp directory and then you can delete files in this local temp directory. After the modification you can upload this zip file to your server.

Code taken from the link above (by Denis Radinski):

using (FileStream zipToOpen = new FileStream(@"C:\Users\Desktop\app.zip", FileMode.Open))
{
    using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
    {
        foreach (var item in archive.Entries)
        {
            if (item.Name.Equals("test.txt"))
            {
                item.Delete();
                break; //needed to break out of the loop
            } // if
        } // foreach
    } // using  
} // using

You need to reference System.IO.Compression.dll.

Matt
  • 25,467
  • 18
  • 120
  • 187