/** * Connect to ftp server * * @return bool * @author Dmitry (dio) Levashov */ public function connect() { static $connected = false; if ($connected) { return true; } if (!($this->connect = ftp_connect($this->options['host'], $this->options['port'], $this->options['timeout']))) { return $this->setError('Unable to connect to FTP server ' . $this->options['host']); } if (!ftp_login($this->connect, $this->options['user'], $this->options['pass'])) { $this->umount(); return $this->setError('Unable to login into ' . $this->options['host']); } // switch off extended passive mode - may be usefull for some servers @ftp_exec($this->connect, 'epsv4 off'); // enter passive mode if required ftp_pasv($this->connect, $this->options['mode'] == 'passive'); // enter root folder if (!ftp_chdir($this->connect, $this->root) || $this->root != ftp_pwd($this->connect)) { $this->umount(); return $this->setError('Unable to open root folder.'); } $connected = parent::connect(); return $connected; }