Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unzip for Perl

Status
Not open for further replies.

weibs

Programmer
Dec 17, 2008
61
US

I am trying to unzip a zip file into a specified directory.
It unzips it, but only extracts 3 of the 7 files that are in it.

This is what I have tried.
Code:
system('unzip ALEtxt_ADN.zip -d db');

Can anyone shed any light why it doesn't extract all of the files?

 
Does it work differently when you run the unzip ALEtxt_ADN.zip -d db command from the shell prompt?

What's the output of unzip -l ALEtxt_ADN.zip?

Annihilannic.
 
May be you can find useful info here:

Code:
What command line parameters does WinZip support?
Below is some information about the undocumented command line options for using the WinZip program module, winzip32.exe. 

WinZip supports command line options to add and extract from files. Be sure to read the Notes section below for additional important information. 

Adding Files
The command format is: 

    winzip32 [-min] action [options] filename[.zip] files

where: 
-min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter. 

action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual. 

options
-r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line. 

-ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password". 

filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder). 

files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed. 

Extracting Files
The command format is: 

    winzip32 -e [options] filename[.zip] folder
where -e is required. 
options
-o and -j stand for "Overwrite existing files without prompting" and "Junk pathnames", respectively. Unless -j is specified, folder information is used. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password". 

filename.zip
Specifies the name of the Zip file involved. Be sure to specify the full filename (including the folder). 

folder
Is the name of the folder to which the files are extracted. If the folder does not exist it is created. 


Notes
VERY IMPORTANT: always specify complete filenames, including the full folder name and drive letter, for all file IDs. 

To run WinZip in a minimized inactive icon use the "-min" option. When specified this option must be the first option. 

Only operations involving the built-in zip and unzip are supported. 

Enclose long filenames in quotes. 

When using a list ("@") file, no leading or trailing spaces should appear in file IDs in the list. 

The action and each option must be separated by at least one space. 

WinZip can be used to compress files with cc:Mail . Change the compress= line in the [cc:Mail] section of the appropriate WMAIL.INI files to specify the full path for WinZip followed by "-a %1 @%2". For example, if WinZip is installed in your c:\winzip folder, specify 
    compress=c:\winzip\winzip.exe -a %1 @%2

dmazzini
GSM/UMTS System and Telecomm Consultant

 
BTE, it is winzip32, Windows..

Cheers

dmazzini
GSM/UMTS System and Telecomm Consultant

 

Hi Annihilannic,

Thank you for your response. Unfortunately I don't have shell access to this server, however when I run it from the software it outputs this to the browser for this code

system('unzip -l ALEtxt_ADN.zip');

Output
Code:
Archive: ALEtxt_ADN.zip Length Date Time Name -------- ---- ---- ---- 790321 07-27-09 21:38 ALE1_ADN.txt 645704 07-27-09 21:39 ALE2_ADN.txt 53760 10-06-03 17:29 ALE_FieldNames.xls 321 07-27-09 21:39 ALE_OpenHouse_ADN.txt 777506 07-27-09 21:39 ALE_PhotoTable_ADN.txt 22946 07-27-09 21:39 ALE_temp_ADN.txt 14848 03-01-06 15:34 temp_data_FieldNames.xls -------- ------- 2305406 7 files

This shows all of the files in the archive, but now it doesn't even extract any of these files into the directory

I also tried
Code:
system('unzip -l ALEtxt_ADN.zip -d db');

To tell it to put it in the db directory but didn't do that either.

Any insight?
 

I also just tried the same code below on two different servers and it extracted the files no problem.
Code:
system('unzip ALEtxt_ADN.zip -d db');

Could this be a server issue? A problem with the unzip program?

Thanks!!
 
Have you tried specifying the full path to the DB directory? Maybe the default directory is not where you expect it to be, and the files are being extracted elsewhere...

What server platform is it? Are all 3 servers the same? And is it the same version of unzip everywhere? (unzip -v should tell you)

Annihilannic.
 
On the one that doesn't work it shows this for the version

Code:
UnZip 5.51 of 22 May 2004, by Info-ZIP. Maintained by C. Spieler. Send bug reports using [URL unfurl="true"]http://www.info-zip.org/zip-bug.html;[/URL] see README for details. Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip/ ; see ftp://ftp.info-zip.org/pub/infozip/UnZip.html for other sites. Compiled with gcc 3.4.6 20060404 (Red Hat 3.4.6-10) for Unix (Linux ELF) on Jul 25 2008. UnZip special compilation options: COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported) LZW_CLEAN (PKZIP/Zip 1.x unshrinking method not supported) SET_DIR_ATTRIB TIMESTAMP USE_EF_UT_TIME USE_DEFLATE64 (PKZIP 4.x Deflate64(tm) supported) VMS_TEXT_CONV [decryption, version 2.9 of 05 May 2000] UnZip and ZipInfo environment options: UNZIP: [none] UNZIPOPT: [none] ZIPINFO: [none] ZIPINFOOPT: [none]

on one that it does work, it shows this for the version
Code:
UnZip 5.51 of 22 May 2004, by Info-ZIP. Maintained by C. Spieler. Send bug reports using [URL unfurl="true"]http://www.info-zip.org/zip-bug.html;[/URL] see README for details. Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip/ ; see ftp://ftp.info-zip.org/pub/infozip/UnZip.html for other sites. Compiled with gcc 3.4.6 20060404 (Red Hat 3.4.6-8) for Unix (Linux ELF) on May 3 2007. UnZip special compilation options: COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported) LZW_CLEAN (PKZIP/Zip 1.x unshrinking method not supported) SET_DIR_ATTRIB TIMESTAMP USE_EF_UT_TIME USE_DEFLATE64 (PKZIP 4.x Deflate64(tm) supported) VMS_TEXT_CONV [decryption, version 2.9 of 05 May 2000] UnZip and ZipInfo environment options: UNZIP: [none] UNZIPOPT: [none] ZIPINFO: [none] ZIPINFOOPT: [none]

The only thing I see that is different between the two are the Red Hat versions.


I also tried specifying the full path to the DB directory but it will still only extract 3 of the 7 files.

Thanks again.
 
That looks fine, running out of ideas now; perhaps try an unzip -t? What output does that give you?

Annihilannic.
 
This is what unzip -t outputs

Code:
UnZip 5.51 of 22 May 2004, by Info-ZIP. Maintained by C. Spieler. Send bug reports using [URL unfurl="true"]http://www.info-zip.org/zip-bug.html;[/URL] see README for details. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] Default action is to extract files in list, except those in xlist, to exdir; file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage). -p extract files to pipe, no messages -l list files (short format) -f freshen existing files, create none -t test compressed archive data -u update files, create if necessary -z display archive comment -x exclude files that follow (in xlist) -d extract files into exdir modifiers: -q quiet mode (-qq => quieter) -n never overwrite existing files -a auto-convert any text files -o overwrite files WITHOUT prompting -aa treat ALL files as text -j junk paths (do not make directories) -v be verbose/print version info -C match filenames case-insensitively -L make (some) names lowercase -X restore UID/GID info -V retain VMS version numbers -M pipe through "more" pager Examples (see unzip.txt for more info): unzip data1 -x joe => extract all files except joe from zipfile data1.zip unzip -p foo | more => send contents of foo.zip via pipe into program more unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
 
Sorry, I meant to include the filename in that command line... i.e. unzip -t ALEtxt_ADN.zip would test the zip contents and print them out.

Annihilannic.
 
ahh ok, here is the output from that then

Code:
Archive: ALEtxt_ADN.zip warning [ALEtxt_ADN.zip]: -8 extra bytes at beginning or within zipfile (attempting to process anyway) error [ALEtxt_ADN.zip]: attempt to seek before beginning of zipfile (please check that you have transferred or created the zipfile in the appropriate BINARY mode and that you have compiled UnZip properly) request = 0x4294967288 (attempting to re-compensate) testing: ALE1_ADN.txt bad CRC 7b26a858 (should be ea4ef177) file #2: bad zipfile offset (local header sig): 107547 (attempting to re-compensate) file #2: bad zipfile offset (local header sig): 107547 file #3: bad zipfile offset (local header sig): 237570 file #4: bad zipfile offset (local header sig): 251378 file #5: bad zipfile offset (local header sig): 251552 testing: ALE_temp_ADN.txt OK testing: temp_data_FieldNames.xls OK At least one error was detected in ALEtxt_ADN.zip.

it still doesn't mention anything about a file that is in there called ALE2_ADN.txt which is the one I need. Well actually I need only 2 files from the zip file which are ALE1_ADN.txt and ALE2_ADN.txt
 
Looks to me like it's simply a corrupt zip file, probably uploaded using FTP in ASCII mode. Try uploading it again perhaps.

You must be in my time zone... or working weird hours. Oz?

Annihilannic.
 

Yes, I will try that. But not tonight, tomorrow sounds better.

And yes, i work weird hours. What time zone are you in?

 
Annihilannic,

Your awesome, it was a corrupt zip file. I downloaded it manually this time and then uploaded via regular ftp and then ran the unzip program and all the files extracted perfectly.

So now I guess I have a problem with my download script.

Care to take a gander?

Code:
my $host = "********";
my $user = "*******";
my $password = "*******";

my $f = Net::FTP->new($host) or die "Can't open $host\n";
$f->login($user, $password) or die "Can't log $user in\n";

print "FTP'd In.... Congrats!!<br><br>";

my $dir = "ADN";

$f->cwd($dir) or die "Can't cwd to $dir\n";

print "Directory: $dir<br>";

my $file_to_get = "ALEtxt_ADN.zip";
my $file_to_put = "ALEtxt_ADN.zip";
print "";
print "Downloaded<br><br>";

$f->get($file_to_get) or die "Can't get $file_to_get from $dir\n";
$f->put($file_to_put) or die "Can't put $file_to_put into $dir\n";

So I'm guessing it's not downloading in binary. How would I make it download in binary?

Thanks!!

ps... from the US- west coast

 
Well I figured out my download problem as well.

Just needed to add in $f->binary;

Now it works like charm.

Thanks again for all your help.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top