I've created a small remote download script which downloads remote files to my server using wget. Now here's how it works: I have a html form, which the user can enter the URL, destination file name, and optionally username and password to authenticate, in case needed. The form calls a php script, using AJAX, and the php script passes the information to a shell script. Now the problem is, the shell script works flawlessly on my local linux machine, but on my server, it doesn't work with authentication(without authentication, it works just fine.)
#!/bin/bash
if test $# -eq 2
then
wget -O "$2" $1
elif test $# -eq 4
then
wget -O "$2" --http-user="$3" --http-password="$4" $1
else
wget $1
fi
it might be worth mentioning that, I own a shared server.
Thanks
EDIT: Is it possible that the version of wget installed on the server, doesn't support http authentications???
EDIT 2: I piped the output of wget to a file like this:
wget -O "$2" --http-user="$3" --http-password="$4" $1 | echo >> output
but the output is empty, i.e. no messages is being printed from wget!!! And I did this too, to check if the credentials passed is ok:
echo "$3 | $4" >> credentials
And it was ok.
And this is the php code which runs the shell script:
if(isset($_POST["startdownload"]))
{
list($url, $dest, $user, $pass) = explode("|", urldecode($_POST["data"]));
$filelen = file_len($url);
$freespace = getRemainingSpace();
//die( "( Free: $freespace, File: $filelen )" );
if($filelen > $freespace - 10000)
{
$result = json_encode(array("error" => true,
"message" => "There is not enough space to download this file. ( Free: $freespace, File: $filelen )"));
die($result);
}
else
{
if($user != "NULL" && $pass != "NULL")
{
execInBackground("../dl.sh '{$url}' '../{$dest}' '{$user}' '{$pass}'| at now");
}
else
{
execInBackground("../dl.sh '{$url}' '../{$dest}' | at now");
}
$result = json_encode(array("error" => false, "message" => "Starting download..."));
die($result);
}
}
function execInBackground($cmd)
{
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}