Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Unzip with password?

by Sec (Scribe)
on Feb 19, 2009 at 00:29 UTC ( #744920=perlquestion: print w/ replies, xml ) Need Help??
Sec has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to pull a file out of a password-protected ZIP file in perl? I searched CPAN for modules, but it appears that all of them lack password functionality. As I don't want to reinvent the wheel: Does anyone have a solution at hand? And if not, how would you approach the problem? As I am running on unix, i can probably fake it by calling the unzip command.

Comment on Unzip with password?
Re: Unzip with password?
by kennethk (Abbot) on Feb 19, 2009 at 01:11 UTC
    Easy, non-Perl solution: `unzip -P $password $archive $file`, where you may want to take precautions on how you encode $password. The lack of password support is likely because ZIP encryption has a known vulnerability.
Re: Unzip with password?
by Anonymous Monk on Feb 19, 2009 at 04:02 UTC
Re: Unzip with password?
by Sec (Scribe) on Apr 01, 2009 at 15:05 UTC
    As there is no appopriate perl module, I'm now doing it this way:
    my $r; { open(ZIP,"-|","/usr/local/bin/unzip -P 'иииииии' -p cache/$zipname $fname") || die "unzip failure"; local($/)=undef; $r=<ZIP>; close(ZIP); };
    Of course you need to make sure that $zipname and $fname contain no evil characters.
      Of course you need to make sure that $zipname and $fname contain no evil characters.

      You don't if you use the array form of open:

      open(ZIP,"-|","/usr/local/bin/unzip" => -P => 'иииииии', -p => "cache/$zipname", $fname, ) || die "unzip failure";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://744920]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-05-31 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (601 votes), past polls