Back to FtpClient class

Method append

public bool
append
(mixed $remote, mixed $buffer)
Method to append a string to the FTP server
Parameters
  • string $remote FTP path to file to append to
  • string $buffer Contents to append to the FTP server
Returns
  • bool True if successful
Since
  • 3.6.0
Class: FtpClient
Project: Joomla

Method append - Source code

/**
 * Method to append a string to the FTP server
 *
 * @param   string  $remote  FTP path to file to append to
 * @param   string  $buffer  Contents to append to the FTP server
 *
 * @return  boolean  True if successful
 *
 * @since   3.6.0
 */
public function append($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) {
            throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_PASSIVE', __METHOD__), 36);
        }
        $tmp = fopen('buffer://tmp', 'bw+');
        fwrite($tmp, $buffer);
        rewind($tmp);
        $size = $this->size($remote);
        if ($size === false) {
        }
        if (@ftp_fput($this->_conn, $remote, $tmp, $mode, $size) === false) {
            fclose($tmp);
            throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_BAD_RESPONSE', __METHOD__), 35);
        }
        fclose($tmp);
        return true;
    }
    // First we need to set the transfer mode
    $this->_mode($mode);
    // Start passive mode
    if (!$this->_passive()) {
        throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_PASSIVE', __METHOD__), 36);
    }
    // Send store command to the FTP server
    if (!$this->_putCmd('APPE ' . $remote, array(150, 125))) {
        @fclose($this->_dataconn);
        throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_NOT_EXPECTED_RESPONSE_150_125', __METHOD__, $this->_response, $remote), 35);
    }
    // Write buffer to the data connection port
    do {
        if (($result = @fwrite($this->_dataconn, $buffer)) === false) {
            throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_DATA_PORT', __METHOD__), 37);
        }
        $buffer = substr($buffer, $result);
    } while ($buffer != '');
    // Close the data connection port [Data transfer complete]
    fclose($this->_dataconn);
    // Verify that the server received the transfer
    if (!$this->_verifyResponse(226)) {
        throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_TRANSFER_FAILED', __METHOD__, $this->_response, $remote), 37);
    }
    return true;
}