Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
What I want to do is this: Copy a couple of folders, which roughly have around 400 files in many diff. directories/sub-directories from a server machine, using ftp (in Windows) to many client machines.
Since I do not know the paths of these files, and since they may change every, say, week, I zip them using Winzip so that I can ftp only the zip file, and unzip them in each of the clients.
I have an ftp script which are placed in each of the client and does the process (using ftp -s).

Now, I want to automate the entire process. The problem is, once I have the Winzip file, and I have them ftp'd to each of the clients, how do I unzip them automatically? I know this is an entirely "winzip" related question, but is there any such alternative in perl? Something like bundle all files/folders to a zip/archive file in the source, and unzip/explode it in the destination.
Many Thanks!

Replies are listed 'Best First'.
Re: FTP folders
by pg (Canon) on Oct 20, 2003 at 05:01 UTC

    Check CPAN module Archive::Zip and other related modules.

    Another way to get the anwser for this question, is to go to www.cpan.org, do a module search by key word "zip". It will give you the answer you want.

    Once you get to the document of the module, you will see a big FAQ list, don't bother it for now. To make it simple, and get yourself started right the way, go straight to those two sections: "how to add a directory/tree to a zip" and "how to extract a directory/tree".

Re: FTP folders
by Roger (Parson) on Oct 20, 2003 at 06:55 UTC
    If I understand correctly, you are looking for something similar to a release distribution process. You are sending files via FTP to each client machine from your server, and you want to know how to kick off the unzip remotely on the client machines from the server (or within FTP).

    Well, to start with, you can't kick off unzip remotely within an FTP session, for obvious security reasons.

    There are a lot of commercial (and free?) products to do remote package/zip releases (such as OnCommand). You will have to do a bit of research on this.

    Or you can write your own Windows service on each of the client to unzip any FTP files in certain predefined directories after they arrive. But that could be a complicated task if you want to do it properly. You need to introduce trigger files with CRC to make sure the FTP is complete, and to be efficient, you probably need to use the system filewatcher instead of a periodic poller.

    If I was to implement the solution, I won't bother with remote processes because they are complicated and not worth the effort. If your data files are not big, you could just write a simple FTP program that runs on your server, and sends all the data files to each of the clients in a list. The following is an outline of the algorithm:

    my @clients; my @files_to_send; foreach my $client(@clients) { my $c = create_FTP_connection($client); foreach my $file(@files_to_send) { $c->Put($file); } close_FTP_connection($c); }
    Update: If you already has the FTP scripts on the clients, then you simply need to do a system($PATH_TO_WINZIP, "filename.zip"); or something alike to extract the zip file. You need to check the Winzip manual to find out the correct parameters to use.

Re: FTP folders
by PriNet (Monk) on Oct 20, 2003 at 06:08 UTC
    you can use the system() function and include the winzip command line options. the command line options shouldn't be to hard to find, email me at gary@prinet.org if you can't find them on the net...


    you mean there's any easier way?
Re: FTP folders
by rupesh (Hermit) on Oct 20, 2003 at 10:25 UTC
    Here's a simple subroutine I use to unzip the contents of a zip file. It's just the basics, but you could do a lot more using the CPAN docs
    #! c:\perl\bin\perl.exe use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use strict; my ($zipfl, $zippath); print "Enter the name of the zip file: \n"; chomp ($zipfl = <stdin>); print "Enter the absolute path where the contents are to be blown up!: + \n"; chomp ($zippath = <stdin>); extract_tree("$zipfl","$zippath"); sub extract_tree($$) { my $source=shift; my $target=shift; chomp ($target); my $zip = Archive::Zip->new(); $zip->read("$source"); $zip->extractTree( "", "$target" ); }
    SRK.