JFTP/listNames: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to list the filenames of the contents of a directory on the FTP server
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFTP/... |
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 109: | Line 109: | ||
<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 124: | Line 124: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API16]] | |||
Revision as of 02:54, 14 May 2013
Description
Method to list the filenames of the contents of a directory on the FTP server
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
listNames($path=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $path | null | $path Path local file to store on the FTP server |
Returns
string Directory listing
Defined in
libraries/joomla/client/ftp.php
Importing
jimport( 'joomla.client.ftp' );
Source Body
function listNames($path = null) {
// Initialise variables.
$data = null;
// 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::listNames: Unable to use passive mode');
return false;
}
if (($list = @ftp_nlist($this->_conn,$path)) === false) {
// Workaround for empty directories on some servers
if ($this->listDetails($path, 'files') === array()) {
return array();
}
JError::raiseWarning('35', 'JFTP::listNames: Bad response');
return false;
}
$list = preg_replace('#^'.preg_quote($path, '#').'[/\\\\]?#', '', $list);
if ($keys = array_merge(array_keys($list, '.'), array_keys($list, '..'))) {
foreach ($keys as $key) {
unset($list[$key]);
}
}
return $list;
}
/*
* If a path exists, prepend a space
*/
if ($path != null) {
$path = ' ' . $path;
}
// Start passive mode
if (!$this->_passive()) {
JError::raiseWarning('36', 'JFTP::listNames: Unable to use passive mode');
return false;
}
if (!$this->_putCmd('NLST'.$path, array (150, 125))) {
@ fclose($this->_dataconn);
// Workaround for empty directories on some servers
if ($this->listDetails($path, 'files') === array()) {
return array();
}
JError::raiseWarning('35', 'JFTP::listNames: Bad response', 'Server response: '.$this->_response.' [Expected: 150 or 125] Path sent: '.$path);
return false;
}
// Read in the file listing.
while (!feof($this->_dataconn)) {
$data .= fread($this->_dataconn, 4096);
}
fclose($this->_dataconn);
// Everything go okay?
if (!$this->_verifyResponse(226)) {
JError::raiseWarning('37', 'JFTP::listNames: Transfer Failed', 'Server response: '.$this->_response.' [Expected: 226] Path sent: '.$path);
return false;
}
$data = preg_split("/[".CRLF."]+/", $data, -1, PREG_SPLIT_NO_EMPTY);
$data = preg_replace('#^'.preg_quote(substr($path, 1), '#').'[/\\\\]?#', '', $data);
if ($keys = array_merge(array_keys($data, '.'), array_keys($data, '..'))) {
foreach ($keys as $key) {
unset($data[$key]);
}
}
return $data;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />