Although the web is full of scripts to help downloading from rapidshare with a premium account, none of them seemed to work for me. First, create a cookie file: curl -k -c .rapidshare -d 'login=USERID&password=PASSWORD' 'https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi'
. In the browser first you click the "premium user" button, second you click "download". We download these pages because the first contains the number of the rapidshare server actually containing the file, like rs123.rapidshare.com and then the mirror like rs123gc3 for Global Crossing.
<?php
define ('COOKIEFILE', '.rapidshare');
$url = $argv[1];
if (!$url) {echo "One argument needed\n";exit;}
$parts = parse_url($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$step1 = curl_exec($ch);
preg_match('|"(http://rs\d+[^"]+)"|', $step1, $match);
$url = $match[1];
$rs = preg_quote('.rapidshare.com');
// Create a preg based on the URL.
$mirror_mask = str_replace(preg_quote($url), $rs, 'action=\'([^.]+' . $rs) .'[^\']+)\'';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'dl.start=PREMIUM&submit=Premium%20user');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEFILE);
$step2 = curl_exec($ch);
preg_match("/$mirror_mask/", $step2, $masks);
$fh = fopen(basename($parts['path']), 'wb');
// It might not be necessary to re-init curl. But it certainly does not hurt.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $masks[1]);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEFILE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
fclose($fh);
?>