JFTP/store: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to store a file to the FTP server
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</now... |
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>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 116: | Line 116: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
| Line 131: | Line 131: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Revision as of 17:21, 12 May 2013
Description
Method to store a file to the FTP server
[<! removed edit link to red link >]
<! 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 edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />