API15

JFTP/listNames

From Joomla! Documentation

< API15:JFTP

The "API15" 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 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[edit]

listNames($path=null)
Parameter Name Default Value Description
$path null $path Path local file to store on the FTP server

Returns[edit]

string Directory listing

Defined in[edit]

libraries/joomla/client/ftp.php

Importing[edit]

jimport( 'joomla.client.ftp' );

Source Body[edit]

function listNames($path = null) {

        // Initialize 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[edit]

Code Examples[edit]