API16

JFTP/getInstance

From Joomla! Documentation

< API16:JFTP

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]

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


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

Syntax[edit]

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

The FTP Client object. 

Defined in[edit]

libraries/joomla/client/ftp.php

Importing[edit]

jimport( 'joomla.client.ftp' );

Source Body[edit]

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 transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]