JFTP/write: Difference between revisions
From Joomla! Documentation
m clean up |
m preparing for archive only |
||
| Line 101: | Line 101: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=write | category=write | ||
category=JFTP | category=JFTP | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 01:38, 25 March 2017
Description
Method to write a string to the FTP server
<! 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 transcluded page call, red link never existed >
Examples
Code Examples