dsdt66064367 2014-05-17 11:11
浏览 37
已采纳

php ftp警告权限

I'm writing a class that will show a list of files and retrieve / send files. I have problem with downloading. I can connect with server, showing list files, but I can't download file.

Warning: ftp_get(index.php): failed to open stream: Permission denied in /var/www/public_html/class.ftp.php on line 51
Warning: ftp_get(): Error opening index.php in /var/www/public_html/class.ftp.php on line 51

When I use application in my PC and this account ftp, I don't have problem with downloading. In principle, I cannot change file permissions, because I will be used multiple ftp. I don't understand, why I don't need change a permission file when I download file with application and PHP needs this permission have.

Code:

protected function connect()
{
    $this->connect=ftp_connect($this->host);
    $result=ftp_login($this->connect, $this->login, $this->pass);
    if($result){
        ftp_pasv($this->connect, true);
        $this->status=true;
    }
    else $this->status=false;
}
public function download_file($path)
{
    $e=explode('/', $path);

    $last=count($e)-1;
    $file=$e[$last];
    $file='download/'.$file;

    return ftp_get($this->connect, $path, $file, FTP_ASCII); //I tried FTP_BINARY
}

Use:

var_dump($conn->download_file('index.php'));

See:

bool(false)

And of course errors.

  • 写回答

1条回答 默认 最新

  • dongyulan6251 2014-05-17 11:49
    关注

    Ok my sweet mistake ;-)

    1) change local file to server file...

    public function download_file($path)
    {
    
        $file='./download/'.$path;
        return ftp_get($this->connect, $file, $path, FTP_BINARY);
    }
    

    2) My local folder "downloads" must have chmod 777

    Sorry

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示