Jump to content

Download file to my hard drive at regular interval


maraki2

Recommended Posts

Hey guys, nice forum here - hope you can help me :) Here is the situation

1. I need to login to an https website using username and password

2. I need to download a zip file which is stored in this https location to my computer's hard drive C:

 

3. I need to do this automatically once every day

 

any help would be much appreciated as i don't know where to start - I read that the best solution would be to use PHP Curl but need help with the syntax.

cheers

Maraki

Link to comment
Share on other sites

cURL is definitely the best solution for sending packets over SSL. Here is a place to start:

$post = 'username=yourname&password=yourpass';
$curl = curl_init('https://www.securesite.com/login');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($curl);

There is a good chance that the end server will be looking for some extra information, possibly in the form of headers. To find out what this information is, use a packet sniffer (like firebug) to find out exactly what information is being sent by the browser.

 

https://getfirebug.com/

http://us2.php.net/manual/en/function.curl-setopt.php

Link to comment
Share on other sites

thanks for the info... i am really a newbie when it comes to cURL.. I found this piece of code but i need to make it so that the file is downloaded to my hard drive...

function get_stats($login_url, $username, $password, $login_button, $csv_title, $download_url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $login_url);
    $post_fields = 'username='.urlencode($username).'&password='.urlencode($password);
    // Some sites don't send this variable, hence the check
    if(trim(urlencode($login_button)) != ''){
        $post_fields .= '&'.$login_button.'='.$login_button;
    }
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
    curl_exec($ch);

    // Prevent the script from timing out
    set_time_limit(0);

    $fp = fopen (dirname(__FILE__) . '/'.$csv_title, 'w+');//This is the file where we save the information
    curl_setopt($ch, CURLOPT_URL, $download_url);//Here is the file we are downloading
    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.