ComponentPro UltimateZip

      Working with FTP File System

      Language Filter: AllSend comments on this topic to ComponentPro

      The following examples demonstrate how to add files from an FTP server to an archive and extract files from an archive onto an FTP server.

      Adding files on an FTP server to a Zip file

      using System;
      using System.Collections.Generic;
      using System.Text;
      using ComponentPro.Compression;
      using ComponentPro.Net;
      using ComponentPro.IO;
      
      ...
      
      // Create a ZIP file.
      Zip zipFile = new Zip();
      
      zipFile.Create(@"c:\test.zip");
      
      Ftp ftp = new Ftp();
      // Connect to the FTP server.
      ftp.Connect("demo.componentpro.com", 21);
      // Authenticate.
      ftp.Authenticate("test", "test");
      // Create a new instance of the TransferOptions class. 
      // There are many advanced option in the TransferOptions class such as Recursive, allowing empty directory creation, etc.
      TransferOptions opt = new TransferOptions();
      // Download files(*.cs, *.vb, and *.exe files) from the root folder to the ZIP file directly.
      ftp.Download("/*.cs;*.vb;*.exe", false, null, zipFile, "", opt);
      ftp.Disconnect();
      
      zipFile.Close();
      

      Extracting files from a Zip file onto an FTP server

      using System;
      using System.Collections.Generic;
      using System.Text;
      using ComponentPro.IO;
      using ComponentPro.Net;
      using ComponentPro.Compression;
      
      ...
      
      // Connect to an FTP file system.
      Ftp ftp = new Ftp();
      ftp.Connect("192.168.126.128", 2222);
      ftp.Authenticate("test", "test");
      
      // Open an existing zip file.
      Zip zip = new Zip();
      
      zip.Open("test.zip");
      
      // Extract and upload all files within the archive to the FTP server. 
      // This operation directly uploads files to the FTP server, no temporary files created.
      zip.ExtractAll(ftp, "", FileOverwriteMode.Overwrite);
      
      zip.Close();
      ftp.Disconnect();