Actions

API16

JFTP/write

From Joomla! Documentation

< API16:JFTP
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 write a string to the FTP server

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

write($remote, $buffer)
Parameter Name Default Value Description
$remote $remote FTP path to file to write to
$buffer $buffer Contents to write to the FTP server

Returns

boolean True if successful

Defined in

libraries/joomla/client/ftp.php

Importing

jimport( 'joomla.client.ftp' );

Source Body

function write($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::write: Unable to use passive mode');
                        return false;
                }
 
                $tmp = fopen('buffer://tmp', 'br+');
                fwrite($tmp, $buffer);
                rewind($tmp);
                if (@ftp_fput($this->_conn, $remote, $tmp, $mode) === false) {
                        fclose($tmp);
                        JError::raiseWarning('35', 'JFTP::write: Bad response');
                        return false;
                }
                fclose($tmp);
                return true;
        }
 
        // First we need to set the transfer mode
        $this->_mode($mode);
 
        // Start passive mode
        if (!$this->_passive()) {
                JError::raiseWarning('36', 'JFTP::write: Unable to use passive mode');
                return false;
        }
 
        // Send store command to the FTP server
        if (!$this->_putCmd('STOR '.$remote, array (150, 125))) {
                JError::raiseWarning('35', 'JFTP::write: Bad response', 'Server response: '.$this->_response.' [Expected: 150 or 125] Path sent: '.$remote);
                @ fclose($this->_dataconn);
                return false;
        }
 
        // Write buffer to the data connection port
        do {
                if (($result = @ fwrite($this->_dataconn, $buffer)) === false) {
                        JError::raiseWarning('37', 'JFTP::write: Unable to write to data port socket');
                        return false;
                }
                $buffer = substr($buffer, $result);
        } while ($buffer != "");
 
        // Close the data connection port [Data transfer complete]
        fclose($this->_dataconn);
 
        // Verify that the server recieved the transfer
        if (!$this->_verifyResponse(226)) {
                JError::raiseWarning('37', 'JFTP::write: Transfer Failed', 'Server response: '.$this->_response.' [Expected: 226] Path sent: '.$remote);
                return false;
        }
 
        return true;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />