我已经创建了一个小的远程下载脚本,它使用wget将远程文件下载到我的服务器。下面是它的工作原理:我有一个html表单,用户可以在需要时输入URL、目标文件名以及用户名和密码进行身份验证。表单使用AJAX调用php脚本,php脚本将信息传递给shell脚本。现在的问题是,shell脚本在我本地的linux机器上可以完美地工作,但在我的服务器上,它不能与身份验证一起工作(没有身份验证,它就能正常工作)。
#!/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值得一提的是,我拥有一台共享服务器。
谢谢
编辑:会不会是服务器上安装的wget版本不支持http身份验证?
编辑2:我将wget的输出通过管道传输到一个文件,如下所示:
wget -O "$2" --http-user="$3" --http-password="$4" $1 | echo >> output但输出为空,即未从wget打印任何消息!我也这样做了,以检查传递的凭据是否正确:
echo "$3 | $4" >> credentials一切都还好。
这是运行shell脚本的php代码:
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 &");
}
} 发布于 2013-05-15 19:38:07
那么,通过system/exec/shell_exec或任何其他脚本运行此脚本,可能会“阻塞”PHP脚本的其余部分。但作为答案,请查看以下内容:http://www.zarafa.com/wiki/index.php/Using_wget_and_HTTP_authentication_for_supported_downloads
wget -O "$2" --user="$3" --ask-password="$4" $1https://stackoverflow.com/questions/16562022
复制相似问题