can';在从php调用时,使用带有身份验证的wget下载文件

can';在从php调用时,使用带有身份验证的wget下载文件,php,shell,Php,Shell,我创建了一个小的远程下载脚本,它使用wget将远程文件下载到我的服务器。 下面是它的工作原理: 我有一个html表单,用户可以输入URL、目标文件名,还可以输入用户名和密码进行身份验证,以备需要。 表单使用AJAX调用php脚本,php脚本将信息传递给shell脚本。 现在的问题是,shell脚本在我本地的linux机器上工作得完美无缺,但在我的服务器上,它不能与身份验证一起工作(没有身份验证,它就可以正常工作) 值得一提的是,我拥有一个共享服务器 谢谢 编辑: 服务器上安装的wget版本是否可

我创建了一个小的远程下载脚本,它使用wget将远程文件下载到我的服务器。 下面是它的工作原理: 我有一个html表单,用户可以输入URL、目标文件名,还可以输入用户名和密码进行身份验证,以备需要。 表单使用AJAX调用php脚本,php脚本将信息传递给shell脚本。 现在的问题是,shell脚本在我本地的linux机器上工作得完美无缺,但在我的服务器上,它不能与身份验证一起工作(没有身份验证,它就可以正常工作)

值得一提的是,我拥有一个共享服务器

谢谢

编辑: 服务器上安装的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 &");  
    }
} 

那么,通过system/exec/shell_exec或任何其他方式运行这个脚本,可能会“阻止”PHP脚本的其余部分。但作为一个答案,请查看以下内容:


出于安全考虑,我希望你能逃出监狱。还有,为什么不使用cURL呢?在HTTP身份验证上也更容易!事实上,我不记得为什么我选择wget而不是卷曲。我最近决定添加身份验证:-)。关于逃跑,问题是,我是唯一会使用它的人,所以不用担心;-)我想我使用了wget,因为curl会阻止php脚本,我想要一些异步的东西,尽管我不确定!谢谢你的回答,克里斯:-)。好的,我向您保证:wget-O“$2”--http user=“$3”--http password=“$4”$1没有任何问题。因为我在本地机器上运行了它。我所能猜到的是,要么安装在那里的wget有问题,要么因为它是一个共享服务器,所以有一些限制。你有任何输出吗?也就是说,你能告诉我你是如何在PHP中执行它的,以及你是如何“获取”结果的吗?如果可能的话,您应该尝试在服务器本身上通过SSH运行它:这样您就可以全面了解“发生了什么”。主要的问题是,它是一个共享服务器,我不能使用SSH。运行shell脚本的php代码已经包含在问题中,您在问题中没有看到任何实际的php代码吗?您是否使用exec、system、shell_exec、popen?在添加注释后,我将其包括在内:-D我不知道您会这么快地查找它;)
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 &");  
    }
} 
wget -O "$2" --user="$3" --ask-password="$4" $1