Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET How to download a specific file located in a Zip archive on a remote FTP server?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20520 |

    Dear Sir,

    I surfed your website, and found that your XCEED Zip for .NET and XCEED FTP for .NET software package both have the capabilities of accessing a specific file (if we know its name in advance) located in a Zip archive on a remote FTP server. Comparatively speaking, I don’t which one is  more suitable for my needs.

    I just download Xceed_.NET_Libraries_v5.4.exe for evaluation purpose. The two candidate are both used for the Microsoft .NET platform, but the pity is that I am not familiar with C# or VB.NET language. Therefore, to speed up my purchase decision, I would like to ask for a simple demo, or a code snippet either in C# or VB.NET language, to help me download a single file located in a Zip archive on a remote anonymous FTP server.

    Thank you in advance. 

    GoldenLee 

    Dear Xceed helpdesk,
    I tested all your C# samples located in “Xceed Samples” directory. There’s no one concerned with downloading a specific file located in a Zip archive on a remote FTP server.
    I was highly impressed with the following cool features (please see their respective selected features cited by me from your website) of your two software packages: XCEED Zip for .NET and XCEED FTP for .NET.

    http://xceed.com/Zip_Net_Features.html (excerpt from Multi-talented capabilities)
    Abstracts files and folders in Zip files, on FTP sites, in streams, in memory, etc., so that your code is written as if it is working with regular files or folders. When support is added for more archive types and locations, there is no need to change your code in order to work with the new archive types or locations.

    It even optimizes operations so that you can perform feats such as speedily accessing files located in a Zip archive on a remote FTP server, while using astonishingly low bandwidth. No other .NET component or combination of components can accomplish this.

    http://xceed.com/FTP_NET_Features.html ( (excerpt from Multi-talented capabilities)
    Abstracts files and folders on FTP sites and locally, in Zip and Tar archives, in GZipped files, in streams, in memory, etc. So you can write your code as if it works with regular files or folders. When support is added for more archive types and locations, there’s no need to change your code in order to work with the new file and folder types or locations.

    It even optimizes operations so that you can perform feats such as speedily accessing files located in a Zip archive on a remote FTP server, while using astonishingly low bandwidth. No other .NET component or combination of components can accomplish this.

    Accessing files located in a Zip archive on a remote FTP server, just time-savingly extracting file(s) of what I want from a very big Zip archive (usually so) on a remote FTP server, rather than time-consumingly downloading the big Zip archive to user’s local host. This is cool feature indeed. As I know, many typical FTP related software components don’t have this kind of feature. Why not write a simple sample program to show your exceptional feature?

    To be frank, I feel a little bit disappointed for my question left unanswered for several days. If the “Forum” is out of place for me to post this kind of question or requirement, please accept my apologies, and do me a favor of telling me whom I can write to. We’d like to buy your XCEED Zip for .NET or XCEED FTP for .NET package as soon as it is proved to meet our aforesaid needs.

    As I mentioned in my previous post, I don’t expect a fully-featured example (It’s my job). A pseudocode snippet (for example, use what kind of methods/propertes in a step by step manner) will be highly appreciated.

    Thank you very much. I’m eagerly looking forward to hearing your programming tips.

    Dear Fawzi Bablli,
    Thank you for your out-of-the-box method. After reading your introduction to the working mechanism (Neither the Ftp nor Zip component perform actual operations on the server.) behind your Ftp or Zip component, I was just about to lose my heart. You mean that the Ftp component will download the zip file, and then the user-specified file will be extracted automatically at the client side. The Ftp or Zip component should perform actual operations on the server side, and locate the starting point of a given file stream packed in tarball archive, and extract that file on demand. I don’t fully understand your words in parentheses, which reads “in the best case scenario, only parts of the zip file will be downloaded”. You mean that your Ftp or Zip component is smarter enough to do some intelligent decision. I mean, if the file of being downloaded happens to be tarred at the beginning of the tarball archive, only parts of the tar archive will be downloaded, if at the bottom half of the tarball archive, the whole tar archive will be downloaded. Am I right?

    I want to extract a dozen or dozens of individual files from the same big tarball archive (packed more than one hundred files, with a size of roughly 2GB) on a remote NOAA/CLASS FTP server (ftp://ftp-npp.class.ngdc.noaa.gov/). I did some modification on the basis of my particular scenario as follows:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Xceed.FileSystem;
    using Xceed.Compression;
    using Xceed.Ftp;
    using Xceed.Ftp.Engine;
    using Xceed.Tar;
    using Xceed.Utils.Collections;

    namespace XceedFtpTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                DownloadFromTarball() ;
            }

            static void DownloadFromTarball()
            {
                // We will connect to the following FTP server anonymously. We will
                // then list the contents of the specified zip file, and unzip its
                // contents to the following local folder.
                string hostname = “ftp-npp.class.ngdc.noaa.gov”;
                string remoteTarFilename = @”/20131201/VIIRS/VIIRS-Moderate-Resolution-Band-01-SDR/VIIRS_VIIRS-Moderate-Resolution-Band-01-SDR_20131201_00001.tar”;
                string localFolder = @”C:\Xceed Samples\”;// System.IO.Path.GetTempPath() + @”SnippetExplorer\”;

                // Always start with an FtpConnection.
                using (FtpConnection connection = new FtpConnection(hostname))
                {
                    // When working on disk, you usually create ZipArchive instances
                    // around a DiskFile. Here, all we need to do is create our ZipArchive
                    // around an FtpFile. The rest of the code does not change.
                    AbstractFile tarFile = new FtpFile(connection, remoteTarFilename);
                    TarArchive archive = new TarArchive(tarFile); // ERROR occurred at this line

                    // And we can copy files stored in that zip file just as you would
                    // copy files from any folder.
                    AbstractFolder destFolder = new DiskFolder(localFolder);

                    // Select a particular file in the archive
                    AbstractFile file = archive.GetFile(@”SVM01_npp_d20131201_t0037197_e0043000_b10848_c20131201064300424091_noaa_ops.h5″);

                    // Copy the remote zipped item to our local folder
                    file.CopyTo(destFolder, true);
                }
            }

        }
    }

    The test program was compiled with no error. But it throwed the following error message when running:
    Unhandled Exception: Xceed.FileSystem.FileSystemException: An error occurred while opening a file for reading.
    Type: Xceed.Ftp.FtpFile
    FullName: \20131201\VIIRS\VIIRS-Moderate-Resolution-Band-01-SDR\VIIRS_VIIRS-Moderate-Resolution-Band-01-SDR_20131201_00001.tar —> Xceed.Ftp.FtpException: An error occurred

    during the execution of a command. See the InnerException property  for details. —> Xceed.Ftp.FtpTimeoutException: The FTP command execution timed-out.
       — End of inner exception stack trace —
       at Xceed.Ftp.Engine.FtpCommand.EndExecute(IAsyncResult asyncResult)
       at Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
       at Xceed.Ftp.FtpClient.ChangeCurrentFolder(String folder)
       at Xceed.Ftp.FtpConnection.AcquireConnection(String workingFolder, Boolean ignoreNonExisting)
       at Xceed.Ftp.FtpStream.UpdateStream()
       — End of inner exception stack trace —
       at Xceed.Tar.TarredFolder..ctor(FileSystemEvents events, Object userData, AbstractFile tarFile, String folderName)
       at Xceed.Tar.TarArchive..ctor(AbstractFile tarFile)
       at XceedFtpTest.Program.DownloadFromTarball() in C:\Users\Gem Lee\Documents\Visual Studio 2010\Projects\XceedFtpTest\XceedFtpTest\Program.cs:line 48
       at XceedFtpTest.Program.Main(String[] args) in C:\Users\Gem Lee\Documents\Visal Studio 2010\Projects\XceedFtpTest\XceedFtpTest\Program.cs:line 19
    Press any key to continue . . .

    I traced the program, and found the error occurred at the line:
    TarArchive archive = new TarArchive(tarFile); // ERROR occurred at this line

    I certainly want to have a test on your Ftp as well as Zip components, and make a final descion by myself. So, I wish you can help to figure out this kind of error.

    BTW, under the remote directory ftp://ftp-npp.class.ngdc.noaa.gov/20131201/VIIRS/VIIRS-Moderate-Resolution-Band-01-SDR/, all files are in pairs. The paired files have the same file name, but different extension. Take the VIIRS_VIIRS-Moderate-Resolution-Band-01-SDR_20131201_00001.tar file for example, there is VIIRS_VIIRS-Moderate-Resolution-Band-01-SDR_20131201_00001.xml, which is a manifest file and list all file names (and other parameters) packed into the corresponding tarball archive.

    Thank you again!

    Imported from legacy forums. Posted by Li (had 1637 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Li,

     

    Here’s a C# example:

    static void Case157484()
    {
      // We will connect to the following FTP server anonymously. We will
      // then list the contents of the specified zip file, and unzip its
      // contents to the following local folder.
      string hostname = “your ftp server name”;
      string remoteZipFilename = @”images\Flowers\Backup\Flowers.zip”;
      string localFolder = System.IO.Path.GetTempPath() + @”SnippetExplorer\”;

      // Always start with an FtpConnection.
      using( FtpConnection connection = new FtpConnection( hostname ) )
      {
        // When working on disk, you usually create ZipArchive instances
        // around a DiskFile. Here, all we need to do is create our ZipArchive
        // around an FtpFile. The rest of the code does not change.
        AbstractFile zipFile = new FtpFile( connection, remoteZipFilename );
        ZipArchive archive = new ZipArchive( zipFile );

        // And we can copy files stored in that zip file just as you would
        // copy files from any folder.
        AbstractFolder destFolder = new DiskFolder( localFolder );

        // Select a particular file in the archive
        AbstractFile file = archive.GetFile( @”\SomeLogicalSubFolderInTheZipArchive\AnotherLogicalSubFolder\SomeFile.dat” );

        // Copy the remote zipped item to our local folder
        file.CopyTo( destFolder, true );
      }
    }

    Keep in mind that extracting from a remote zip archive is not an efficient operation. There is no magic here. Neither the Ftp or Zip component perform actual operations on the server. The Ftp component will download the zip file (in the best case scenario, only parts of the zip file will be downloaded) and the item will be extracted by the client machine’s processor.

    If your intend is to extract a small single file from time to time, this will work fine. If, however, you plan to extract several individual files from the same archive, you will find that it is more efficient if the entire zip file is download in a temporary local folder and the required items are extracted.

    You have a 45-day trial period, use it to evaluate if the components work well for your particular scenario. 

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 812 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.