protected function exec($cmd)
    {
        if (false === $stream = ssh2_exec($this->con, $cmd)) {
            throw new SshException(sprintf('"%s" : SSH command failed', $cmd));
        }

        stream_set_blocking($stream, true);

        $data = '';
        while ($buf = fread($stream, 4096)) {
            $data .= $buf;
        }

        fclose($stream);

        return $data;
    }