API16:JFTP/store
From Joomla! Documentation
Description
Method to store a file to the FTP server
<! removed transcluded page call, red link never existed >
Syntax
store($local, $remote=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $local | $local Path to local file to store on the FTP server | |
| $remote | null | $remote FTP path to file to create |
Returns
boolean True if successful
Defined in
libraries/joomla/client/ftp.php
Importing
jimport( 'joomla.client.ftp' );
Source Body
function store($local, $remote = null) {
// If remote file not given, use the filename of the local file in the current
// working directory
if ($remote == null) {
$remote = basename($local);
}
// 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::store: Unable to use passive mode');
return false;
}
if (@ftp_put($this->_conn, $remote, $local, $mode) === false) {
JError::raiseWarning('35', 'JFTP::store: Bad response');
return false;
}
return true;
}
$this->_mode($mode);
// Check to see if the local file exists and open for reading if so
if (@ file_exists($local)) {
$fp = fopen($local, "rb");
if (!$fp) {
JError::raiseWarning('38', 'JFTP::store: Unable to open local file for reading', 'Local path: '.$local);
return false;
}
} else {
JError::raiseWarning('38', 'JFTP::store: Unable to find local path', 'Local path: '.$local);
return false;
}
// Start passive mode
if (!$this->_passive()) {
@ fclose($fp);
JError::raiseWarning('36', 'JFTP::store: Unable to use passive mode');
return false;
}
// Send store command to the FTP server
if (!$this->_putCmd('STOR '.$remote, array (150, 125))) {
@ fclose($fp);
@ fclose($this->_dataconn);
JError::raiseWarning('35', 'JFTP::store: Bad response', 'Server response: '.$this->_response.' [Expected: 150 or 125] Path sent: '.$remote);
return false;
}
// Do actual file transfer, read local file and write to data port connection
while (!feof($fp)) {
$line = fread($fp, 4096);
do {
if (($result = @ fwrite($this->_dataconn, $line)) === false) {
JError::raiseWarning('37', 'JFTP::store: Unable to write to data port socket');
return false;
}
$line = substr($line, $result);
} while ($line != "");
}
fclose($fp);
fclose($this->_dataconn);
if (!$this->_verifyResponse(226)) {
JError::raiseWarning('37', 'JFTP::store: Transfer Failed', 'Server response: '.$this->_response.' [Expected: 226] Path sent: '.$remote);
return false;
}
return true;
}
<! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />