elFinderVolumeFTP::connect PHP Method

connect() protected method

Connect to ftp server
Author: Dmitry (dio) Levashov
protected connect ( ) : boolean
return boolean
    protected function connect()
    {
        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']);
        }
        // try switch utf8 mode
        if ($this->encoding) {
            ftp_raw($this->connect, 'OPTS UTF8 OFF');
        } else {
            ftp_raw($this->connect, 'OPTS UTF8 ON');
        }
        // switch off extended passive mode - may be usefull for some servers
        ftp_raw($this->connect, 'epsv4 off');
        // enter passive mode if required
        $pasv = $this->options['mode'] == 'passive';
        if (!ftp_pasv($this->connect, $pasv)) {
            if ($pasv) {
                $this->options['mode'] = 'active';
            }
        }
        // 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.');
        }
        // check for MLST support
        $features = ftp_raw($this->connect, 'FEAT');
        if (!is_array($features)) {
            $this->umount();
            return $this->setError('Server does not support command FEAT.');
        }
        foreach ($features as $feat) {
            if (strpos(trim($feat), 'MLST') === 0) {
                $this->MLSTsupprt = true;
                break;
            }
        }
        return true;
    }