Hi!

Im gonan try to help you, cause Im doing the same. Getting certain files from 
a FTP Server, saving them in a directory already defined, unziping them in a 
temp directory, parsing the file (thanks to all the list), and saving some 
data to a MySql DataBase.


> Data.txt is apx 170MB
> Data.txt is zipped into 'data.zip' which is 18MB
> File 'data.zip' is ftped from winders to unix server
Here you will need Net::FTP, access the FTP Server, and download just the Zip 
Files to a directory.

my $ftp = Net::FTP->new($this->{CONFIG_SERVIDORFTP});
#Log in
$ftp->login($this->{CONFIG_USUARIOFTP}, $this->{CONFIG_PASSWORDFTP});
#Go to the directory where the Zips are
$ftp->cwd($this->{CONFIG_DIRZIPSFTP});
#Ftp to binary
$ftp->binary();
#Save a List of Files
my @lista_zips = $ftp->ls($this->{CONFIG_DIRZIPSFTP});
#Get total of Zips
my $total_zips = @lista_zips;
#Start working just if there are Zip Files
    if($total_zips != 0) {
#Start looking for the files
        foreach (@lista_zips) {
#Look for the files that contains the ext. zip
            if($_ =~ /.zip/i) {
#Download the file to a directory
                $ftp->get($_,"$this->{CONFIG_DIRRECEP}/$_");
#Delete the file from the Ftp
                $ftp->delete($_);
            }
        }
    }
#Exit Ftp
    $ftp->quit();

However, after all this, I check with File::MMagic, if those were really Zip 
Files, if a file just have the ext of zip but its not a Zip File I remove it.

> Now heres' where my perl script comes in:

> Perl/Archive::Zip (or other module???)
Yes.. Archive::Zip
Its easy, Cause I dont know if the files that are inside the zip will appear 
in a directory, Im going to unzip it in a Directory with the same name of the 
Zip (obvious, remove the .zip ext), but You could do it with basename.

sub descomprimir_zip {
    my $this = shift;
#Lenght of the File
    my $letrasarchivo = length($this->{FILE_ZIP});
#extract the name, before the .zip or .ZIP
    my $this->{FILE_SZIP} = substr($file, 0, $letrasarchvio-4);
#Create the directory where Im going to unzip it
    my $this->{DIR_DESCZIP} = $dir_desczip = 
$this->{CONFIG_DIRPRINCIPAL}."/".$_[0]."/".$this->{FILE_SZIP};
#Wheres the f*** zip fIle?
    my $dir_pathzip = 
$this->{CONFIG_DIRPRINCIPAL}."/".$this->{CONFIG_DIRRECEP};
#Create the $zip object
    my $zip = Archive::Zip->new();
#Where is the file?
    $zip->read($dir_pathzip."/".$this->{FILE_ZIP});
#Unzip it in $this->{DIR_DESCZIP}, Im adding a /, so $zip, knows that it will 
be a directory.
    $zip->extractTree('', $this->{DIR_DESCZIP}."/");
#Exit of Zip, just undef $zip (its not necessary)
    $zip = undef;
}

And thats all, Your files will be in DIR_DESCZIP, now open the file, and write 
it to other file (OPEN ">"), (OPEN "<").

Pablo
-- 
Pablo Fischer Sandoval ([EMAIL PROTECTED])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to