Actions

API15

JFTP/read

From Joomla! Documentation

< API15:JFTP
Revision as of 12:29, 25 March 2010 by Doxiki (Talk | contribs)

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to read a file from the FTP server's contents into a buffer

[Edit Descripton]

Description:JFTP/read

Syntax

read($remote, &$buffer)
Parameter Name Default Value Description
$remote $remote Path to remote file to read on the FTP server
&$buffer $buffer Buffer variable to read file contents into

Returns

boolean True if successful

Defined in

libraries/joomla/client/ftp.php

Importing

jimport( 'joomla.client.ftp' );

Source Body

function read($remote, &$buffer) {
 
        // Determine file type
        $mode = $this->_findMode($remote);
 
        // If native FTP support is enabled lets use it...
        if (FTP_NATIVE) {
                // turn passive mode on
                if (@ftp_pasv($this->_conn, true) === false) {
                        JError::raiseWarning('36', 'JFTP::read: Unable to use passive mode' );
                        return false;
                }
 
                $tmp = fopen('buffer://tmp', 'br+');
                if (@ftp_fget($this->_conn, $tmp, $remote, $mode) === false) {
                        fclose($tmp);
                        JError::raiseWarning('35', 'JFTP::read: Bad response' );
                        return false;
                }
                // Read tmp buffer contents
                rewind($tmp);
                $buffer = '';
                while (!feof($tmp)) {
                        $buffer .= fread($tmp, 8192);
                }
                fclose($tmp);
                return true;
        }
 
        $this->_mode($mode);
 
        // Start passive mode
        if (!$this->_passive()) {
                JError::raiseWarning('36', 'JFTP::read: Unable to use passive mode' );
                return false;
        }
 
        if (!$this->_putCmd('RETR '.$remote, array (150, 125))) {
                @ fclose($this->_dataconn);
                JError::raiseWarning('35', 'JFTP::read: Bad response', 'Server response: '.$this->_response.' [Expected: 150 or 125] Path sent: '.$remote );
                return false;
        }
 
        // Read data from data port connection and add to the buffer
        $buffer = '';
        while (!feof($this->_dataconn)) {
                $buffer .= fread($this->_dataconn, 4096);
        }
 
        // Close the data port connection
        fclose($this->_dataconn);
 
        // Let's try to cleanup some line endings if it is ascii
        if ($mode == FTP_ASCII) {
                $buffer = preg_replace("/".CRLF."/", $this->_lineEndings[$this->_OS], $buffer);
        }
 
        if (!$this->_verifyResponse(226)) {
                JError::raiseWarning('37', 'JFTP::read: Transfer Failed', 'Server response: '.$this->_response.' [Expected: 226] Path sent: '.$remote );
                return false;
        }
 
        return true;
}

[Edit See Also] SeeAlso:JFTP/read

Examples

<CodeExamplesForm />