public function read($remote, &$buffer)
	{
		// Determine file type
		$mode = $this->_findMode($remote);

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

				return false;
			}

			$tmp = fopen('buffer://tmp', 'br+');

			if (@ftp_fget($this->conn, $tmp, $remote, $mode) === false)
			{
				fclose($tmp);
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				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())
		{
			Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

			return false;
		}

		if (!$this->_putCmd('RETR ' . $remote, array(150, 125)))
		{
			@ fclose($this->dataconn);
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $remote),
				Log::WARNING, 'jerror'
			);

			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)
		{
			$os = 'UNIX';

			if (defined('PHP_WINDOWS_VERSION_MAJOR'))
			{
				$os = 'WIN';
			}

			$buffer = preg_replace("/" . CRLF . "/", $this->lineEndings[$os], $buffer);
		}

		if (!$this->_verifyResponse(226))
		{
			Log::add(
				sprintf(
					'%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Restart point sent: %3$s',
					__METHOD__, $this->response, $remote
				),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		return true;
	}
public function read($remote, &$buffer)
	{
		// Determine file type
		$mode = $this->_findMode($remote);

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

				return false;
			}

			$tmp = fopen('buffer://tmp', 'br+');

			if (@ftp_fget($this->conn, $tmp, $remote, $mode) === false)
			{
				fclose($tmp);
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				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())
		{
			Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

			return false;
		}

		if (!$this->_putCmd('RETR ' . $remote, array(150, 125)))
		{
			@ fclose($this->dataconn);
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $remote),
				Log::WARNING, 'jerror'
			);

			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)
		{
			$os = 'UNIX';

			if (defined('PHP_WINDOWS_VERSION_MAJOR'))
			{
				$os = 'WIN';
			}

			$buffer = preg_replace("/" . CRLF . "/", $this->lineEndings[$os], $buffer);
		}

		if (!$this->_verifyResponse(226))
		{
			Log::add(
				sprintf(
					'%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Restart point sent: %3$s',
					__METHOD__, $this->response, $remote
				),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		return true;
	}
public function read ( $ remote , & $ buffer ) { // Determine file type $ mode = $ this -> _findMode ( $ remote ) ; // If native FTP support is enabled let's use it... if ( FTP_NATIVE ) { // Turn passive mode on if ( @ ftp_pasv ( $ this -> conn , true ) === false ) { Log :: add ( __METHOD__ . ': Unable to use passive mode.' , Log :: WARNING , 'jerror' ) ; return false ; } $ tmp = fopen ( 'buffer://tmp' , 'br+' ) ; if ( @ ftp_fget ( $ this -> conn , $ tmp , $ remote , $ mode ) === false ) { fclose ( $ tmp ) ; Log :: add ( __METHOD__ . 'Bad response.' , Log :: WARNING , 'jerror' ) ; 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 ( ) ) { Log :: add ( __METHOD__ . ': Unable to use passive mode.' , Log :: WARNING , 'jerror' ) ; return false ; } if ( ! $ this -> _putCmd ( 'RETR ' . $ remote , array ( 150 , 125 ) ) ) { @ fclose ( $ this -> dataconn ) ; Log :: add ( sprintf ( '%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s' , __METHOD__ , $ this -> response , $ remote ) , Log :: WARNING , 'jerror' ) ; 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 ) { $ os = 'UNIX' ; if ( defined ( 'PHP_WINDOWS_VERSION_MAJOR' ) ) { $ os = 'WIN' ; } $ buffer = preg_replace ( "/" . CRLF . "/" , $ this -> lineEndings [ $ os ] , $ buffer ) ; } if ( ! $ this -> _verifyResponse ( 226 ) ) { Log :: add ( sprintf ( '%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Restart point sent: %3$s' , __METHOD__ , $ this -> response , $ remote ) , Log :: WARNING , 'jerror' ) ; return false ; } return true ; }
Method to read a file from the FTP server's contents into a buffer

@param   string  $remote   Path to remote file to read on the FTP server
@param   string  &$buffer  Buffer variable to read file contents into

@return  boolean  True if successful

@since   1.0
Method to read a file from the FTP server s contents into a buffer