public function connect()
    {
        $this->errorHandler->start();
        $methods = array();
        if ($this->configuration->getAuthType() !== 'pass') {
            $methods['hostkey'] = $this->configuration->getAuthType();
        }
        if (($this->sshResource = $this->driver->connect($this->configuration->getHost(), $this->configuration->getPort(), $methods)) !== false) {
            //connected
            if ($this->configuration->getAuthType() !== 'pass') {
                $auth = $this->driver->authPubkey(
                    $this->sshResource, $this->configuration->getUser(), $this->configuration->getPubKey(), $this->configuration->getPrivKey(), $this->configuration->getPassphrase());
            } else {
                $auth = $this->driver->authPassword($this->sshResource, $this->configuration->getUser(), $this->configuration->getPass());
            }
            if ($auth !== false) {
                //logged in
                if (($this->resource = $this->driver->sftpStart($this->sshResource)) !== false) {
                    //started sftp
                    if (($this->dir = $this->driver->realpath($this->resource, $this->configuration->getDir())) !== false) {
                        //changed dir
                        $this->errorHandler->stop();

                        return true;
                    }
                    //could not enter dir
                }
                //could not start sftp
            }
            //Could not log in
        }

        //Could not connect to host/port
        $this->errorHandler->stop();

        return false;
    }