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 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)