douqu8828 2013-01-16 09:29
浏览 29

PHP。 使用流或自定义ftp包装从FTP下载

I need help with creation of custom FTP wrapper in PHP.

I used

$h=fopen('ftp://....');

But this doesn't work well with all FTP servers (sometimes problems with active/passive mode) and i can not control this with the wrapper.

I use functions from http://php.net/manual/en/book.ftp.php and all works fine. I have problems only with download with PHP FTP wrapper.

I need to use wrapper because i don't want to store downloaded file to the disk. I read part of a file from a stream and then output to a user browser.

So i want to create custom FTP wrapper in PHP. And best of all if it is based on functions from there http://php.net/manual/en/book.ftp.php .

I see example there http://php.net/manual/en/function.ftp-fget.php

function ftp_get_contents ($conn_id, $filename, 
//Create temp handler: 
     $tempHandle = fopen('php://temp', 'r+'); 

//Get file from FTP assuming that it exists: 
     ftp_fget($conn_id, $tempHandle, $filename, FTP_ASCII, 0)); 

     //Getting detailed stats to check filesize: 
     $fstats = fstat($tempHandle); 

     return fread($tempHandle, $fstats['size']); 
 }

But this is not good as it saves full file to the disk and only after this i can read from the local file.

DO you know something like this but allows me to read file with portions from FTP server without caching full file locally?

Thanks.

  • 写回答

1条回答 默认 最新

  • dtlab08822 2013-01-17 13:37
    关注

    I found a solution.

    i do

    $h=popen('wget -q -O - ftp://.....','r');
    

    it works fine. But wget must be installed.

    评论

报告相同问题?

悬赏问题

  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了