API16

JFTP/write

From Joomla! Documentation

< API16:JFTP
Revision as of 17:39, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Method to write a string to the FTP server <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</n...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to write a string to the FTP server

[Edit Descripton]

Template:Description:JFTP/write

Syntax[edit]

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[edit]

boolean True if successful

Defined in[edit]

libraries/joomla/client/ftp.php

Importing[edit]

jimport( 'joomla.client.ftp' );

Source Body[edit]

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;
}

[Edit See Also] Template:SeeAlso:JFTP/write

Examples[edit]

<CodeExamplesForm />