API16

Difference between revisions of "JFTP/write"

From Joomla! Documentation

< API16:JFTP
(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...)
 
m (removing red link to edit, no existant pages)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFTP/write|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFTP/write}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 100: Line 100:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFTP/write|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFTP/write}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 115: Line 115:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Revision as of 21:55, 13 May 2013

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

[<! removed edit link to red link >]

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

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

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

Examples[edit]

<CodeExamplesForm />