Ftp::__construct PHP Method

__construct() public method

public __construct ( $url = NULL, $passiveMode = TRUE )
    public function __construct($url = NULL, $passiveMode = TRUE)
    {
        if (!extension_loaded('ftp')) {
            throw new Exception('PHP extension FTP is not loaded.');
        }
        if ($url) {
            $parts = parse_url($url);
            if (!isset($parts['scheme']) || !in_array($parts['scheme'], array('ftp', 'ftps', 'sftp'))) {
                throw new InvalidArgumentException('Invalid URL.');
            }
            $func = $parts['scheme'] === 'ftp' ? 'connect' : 'ssl_connect';
            $this->{$func}($parts['host'], empty($parts['port']) ? NULL : (int) $parts['port']);
            $this->login(urldecode($parts['user']), urldecode($parts['pass']));
            $this->pasv((bool) $passiveMode);
            if (isset($parts['path'])) {
                $this->chdir($parts['path']);
            }
        }
    }

Usage Example

Example #1
0
 /**
  * __construct
  * @param mixed $id
  * @param string $table
  * @param string $ds
  */
 public function __construct($id = null, $table = null, $ds = null)
 {
     ConnectionManager::create($this->useDbConfig, array('datasource' => 'Ftp.FtpTestSource', 'host' => 'localhost', 'username' => 'user', 'password' => '1234', 'type' => 'ftp', 'cache' => false));
     parent::__construct($id, $table, $ds);
 }