API15:JFTP/getInstance
From Joomla! Documentation
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
Code Examples