Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 (Monsignor) 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 studying the Monastery: (10)
As of 2014-12-26 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls