JFTP/store
From Joomla! Documentation
< API16:JFTPRevision as of 21:55, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
Revision as of 21:55, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
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 store a file to the FTP server
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
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[edit]
boolean True if successful
Defined in[edit]
libraries/joomla/client/ftp.php
Importing[edit]
jimport( 'joomla.client.ftp' );
Source Body[edit]
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 edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />