Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Unzip with password?

by Sec (Monk)
on Feb 19, 2009 at 00:29 UTC ( [id://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.

Replies are listed 'Best First'.
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 (Monk) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-03-29 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found