Actions

API15

JFTP/getInstance

From Joomla! Documentation

< API15:JFTP
Revision as of 12:20, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Returns a reference to the global FTP connector object, only creating it if it doesn't already exist.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

& getInstance($host= '127.0.0.1', $port= '21', $options=null, $user=null, $pass=null)
Parameter Name Default Value Description
$host '127.0.0.1' $host Host to connect to
$port '21' $port Port to connect to
$options null FTP_ASCII|FTP_BINARY], timeout=>(int)
$user null $user Username to use for a connection
$pass null $pass Password to use for a connection

Returns

The FTP Client object. 

Defined in

libraries/joomla/client/ftp.php

Importing

jimport( 'joomla.client.ftp' );

Source Body

function &getInstance($host = '127.0.0.1', $port = '21', $options = null, $user = null, $pass = null)
{
        static $instances = array();
 
        $signature = $user.':'.$pass.'@'.$host.":".$port;
 
        // Create a new instance, or set the options of an existing one
        if (!isset ($instances[$signature]) || !is_object($instances[$signature])) {
                $instances[$signature] = new JFTP($options);
        } else {
                $instances[$signature]->setOptions($options);
        }
 
        // Connect to the server, and login, if requested
        if (!$instances[$signature]->isConnected()) {
                $return = $instances[$signature]->connect($host, $port);
                if ($return && $user !== null && $pass !== null) {
                        $instances[$signature]->login($user, $pass);
                }
        }
 
        return $instances[$signature];
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />