public function __call($name, $args)
{
$name = strtolower($name);
$silent = strncmp($name, 'try', 3) === 0;
$func = $silent ? substr($name, 3) : $name;
$func = 'ftp_' . (isset(self::$aliases[$func]) ? self::$aliases[$func] : $func);
if (!function_exists($func)) {
throw new Exception("Call to undefined method Ftp::{$name}().");
}
$this->errorMsg = NULL;
set_error_handler(array($this, '_errorHandler'));
if ($func === 'ftp_connect' || $func === 'ftp_ssl_connect') {
$this->state = array($name => $args);
$this->resource = call_user_func_array($func, $args);
$res = NULL;
} elseif (!is_resource($this->resource)) {
restore_error_handler();
throw new FtpException("Not connected to FTP server. Call connect() or ssl_connect() first.");
} else {
if ($func === 'ftp_login' || $func === 'ftp_pasv') {
$this->state[$name] = $args;
}
array_unshift($args, $this->resource);
$res = call_user_func_array($func, $args);
if ($func === 'ftp_chdir' || $func === 'ftp_cdup') {
$this->state['chdir'] = array(ftp_pwd($this->resource));
}
}
restore_error_handler();
if (!$silent && $this->errorMsg !== NULL) {
if (ini_get('html_errors')) {
$this->errorMsg = html_entity_decode(strip_tags($this->errorMsg));
}
if (($a = strpos($this->errorMsg, ': ')) !== FALSE) {
$this->errorMsg = substr($this->errorMsg, $a + 2);
}
throw new FtpException($this->errorMsg);
}
return $res;
}