PHP. Download from FTP with stream or custom ftp wrapper
<p>I need help with creation of custom FTP wrapper in PHP.</p>

<p>I used </p>

<pre><code>$h=fopen('ftp://....');
</code></pre>

<p>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.</p>

<p>I use functions from <a href="http://php.net/manual/en/book.ftp.php" rel="nofollow">http://php.net/manual/en/book.ftp.php</a> and all works fine. I have problems only with download with PHP FTP wrapper.</p>

<p>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.</p>

<p>So i want to create custom FTP wrapper in PHP. And best of all if it is based on functions from there <a href="http://php.net/manual/en/book.ftp.php" rel="nofollow">http://php.net/manual/en/book.ftp.php</a> .</p>

<p>I see example there <a href="http://php.net/manual/en/function.ftp-fget.php" rel="nofollow">http://php.net/manual/en/function.ftp-fget.php</a></p>

<pre><code>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']); 
 }
</code></pre>

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

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

<p>Thanks.</p>
