/    Sign up×
Community /Pin to ProfileBookmark

Password Protected Zip Files …

I have a script. It is an ftp script.

[LIST=1]

  • [*]

    It goes out to a server and finds me two files that I need.


  • [*]

    Downloads these files


  • [*]

    Unzips these two files


  • [/LIST]

    Number 3 I am having issues with. This is a linux server, and for some reason I can’t use the simple shell_exec functions to do this. It also does not throw any errors.

    Any ideas ya’ll? I am attaching a zip file for troubleshooting purposes.

    MLSRetireveBeta.php

    [code=php]
    <?php
    ini_set(“display_errors”, “1”);
    error_reporting(E_ALL);

    // set up basic connection
    $ftp_server = “somedomain.com”;
    $conn_id = ftp_connect($ftp_server);

    // login with username and password
    if ((!$conn_id) )
    {
    print “FTP connection has Failed!”;
    exit;
    }
    else
    {
    $ftp_user_name = “anonymous”;
    $ftp_user_pass = “[email protected]”;
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    }

    //Turn passive mode on
    ftp_pasv($conn_id, true);

    //Removed so it won’t die.
    if(!$login_result)
    {
    print “<b>Login has Failed! “.$ftp_server.” for user “.$ftp_user_name.”.</b><br/>”;
    }
    else
    {
    print “<br/>Connected to: <em>”.$ftp_server.”</em>”;
    //$good would be true if I am able to navigate to folder, but it is false indicating it cannot navigate to directory
    $good = ftp_chdir($conn_id, ‘/DataLinkOutput/ERI/ERI_1000001334’);

    // print the current direwctory out, results in nothing
    print “<br/>Current directory: <em>” . ftp_pwd($conn_id) . “</em>”;

    //Get the list of files
    $arrDirContents = ftp_nlist($conn_id, ‘.’);
    //Sort it
    natcasesort($arrDirContents);

    //Loop through to find the ones I want
    foreach($arrDirContents as $x)
    {
    //Only residential and commercial files
    if(strpos($x,”_RES_”) > 0 || strpos($x,”_COM_”) > 0 )
    {
    //Only zips
    if(strpos($x,”.zip”) > 0 )
    {
    //only MLS Fulls
    if(strpos(” “.$x,”MF”) > 0 )
    {
    //For Residential
    if(strpos($x,”_RES_”) > 0 )
    {
    $ResidentialFileName = $x;
    }
    //For Commercial
    else
    {
    $BusinessFileName = $x;
    }
    }
    }
    }
    }

    //Check to see if we have ourselves some file names
    if($ResidentialFileName != “” && $BusinessFileName != “” )
    {
    print(“<br/><br/>Found residential file: <i>” . $ResidentialFileName.”</i>”);
    print(“<br/>Found commercial file: <i>” . $BusinessFileName.”</i>”);

    //Download
    if(ftp_get($conn_id, $ResidentialFileName, $ResidentialFileName, FTP_BINARY))
    print(“<br/><br/>Downloaded residential file: <i>” . $ResidentialFileName.”</i>”);
    if(ftp_get($conn_id, $BusinessFileName, $BusinessFileName, FTP_BINARY))
    print(“<br/>Downloaded commercial file: <i>” . $BusinessFileName.”</i>”);

    //Unzip
    if(shell_exec(‘unzip -P ERIE $ResidentialFileName’))
    print(“Unzipped residential file: <i>” . $ResidentialFileName.”</i>”);
    if(shell_exec(‘unzip -P ERIE $BusinessFileName’))
    print(“Unzipped commercial file: <i>” . $BusinessFileName.”</i>”);
    }
    else
    {
    if($ResidentialFileName == “”)
    print “<br/>Residential file missing”;
    if($BusinessFileName == “” )
    print “<br/>Business file missing”;
    }
    }

    ftp_close($conn_id);

    ?>

    [/code]

    [upl-file uuid=ca01d644-2afe-489d-9711-fb01b52f6247 size=34kB]MF20100713_030456_COM_1.zip[/upl-file]

    to post a comment
    PHP

    9 Comments(s)

    Copy linkTweet thisAlerts:
    @Markbad311authorJul 14.2010 — I have also tried:

    [code=php] //Unzip
    if(exec('unzip -P ERIE -u $ResidentialFileName'))
    print("Unzipped residential file: <i>" . $ResidentialFileName."</i>");
    if(exec('unzip -P ERIE -u $BusinessFileName'))
    print("Unzipped commercial file: <i>" . $BusinessFileName."</i>");[/code]
    Copy linkTweet thisAlerts:
    @sohguanhJul 14.2010 — I have also tried:
    [code=php] //Unzip
    if(exec('unzip -P ERIE -u $ResidentialFileName'))
    print("Unzipped residential file: <i>" . $ResidentialFileName."</i>");
    if(exec('unzip -P ERIE -u $BusinessFileName'))
    print("Unzipped commercial file: <i>" . $BusinessFileName."</i>");[/code]
    [/QUOTE]


    First you can test if the exec command can be run at the Unix shell by itself. If it cannot then calling exec from PHP code will fail logically.

    unzip -P ERIE -u <filename.zip>

    Above unzip command execute in Unix shell works ?
    Copy linkTweet thisAlerts:
    @criterion9Jul 14.2010 — Have you tried using double quotes in place of single quotes? Or possible concatenating the variables in your string? Maybe try echoing out the command as a whole to see if it is as you expect.
    Copy linkTweet thisAlerts:
    @Markbad311authorJul 14.2010 — 
    unzip -P ERIE -u <filename.zip>

    Above unzip command execute in Unix shell works ?[/QUOTE]


    I am on a hosting platform that will not allow me to run on the shell. I do have cpanel though.

    Have you tried using double quotes in place of single quotes? Or possible concatenating the variables in your string? Maybe try echoing out the command as a whole to see if it is as you expect.[/QUOTE]

    Yes I have tried dbl quotes, echoing: it returns and empty string. Not what I expected ?


    I also just tried this on my external server:
    [code=php]
    system('unzip -o -P ERIE ' . $file);
    [/code]


    and it failed saying System() was turned off for security purposes.


    What other options do I have? I need this task as a CRON bad.
    Copy linkTweet thisAlerts:
    @criterion9Jul 14.2010 — If you are already able to create cron entries why not use a bash file and skip the php security protections?
    Copy linkTweet thisAlerts:
    @Markbad311authorJul 14.2010 — If you are already able to create cron entries why not use a bash file and skip the php security protections?[/QUOTE]

    I don't know how to do that or what a bash file is without researching. I can set up a .php file to be called. but that would keep the restrictions wouldn't it?
    Copy linkTweet thisAlerts:
    @criterion9Jul 14.2010 — You won't be able to use any disabled functions (system being one of them). What about exec? Is that disabled as well? (anything you type at the command line is probably bash.)
    Copy linkTweet thisAlerts:
    @Markbad311authorJul 14.2010 — You won't be able to use any disabled functions (system being one of them). What about exec? Is that disabled as well? (anything you type at the command line is probably bash.)[/QUOTE]

    I have no command line access.


    shell_exec('unzip -P PASSWORD-u $file') return nothing, and do not throw any errors.

    exec('unzip -P PASSWORD-u $file') return nothing, and do not throw any errors.

    system('unzip -o -P PASSWORD' . $file); returns a permissions error

    What other options do I have ?


    At best I have cPanel Access
    Copy linkTweet thisAlerts:
    @criterion9Jul 14.2010 — Do you have error reporting turned on to an appropriate level? Maybe it is actually throwing errors but it is suppressing them so you don't see?
    ×

    Success!

    Help @Markbad311 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...