public function exec($command)
    {
        if ( ! ($stream = ssh2_exec($this->connection, $command))) {

            throw new Ssh2CommandException("Exec failed: '{$command}'.");
        }

        stream_set_blocking($stream, true);

        $data = '';

        while ($buf = fread($stream, 4096)) {

            $data .= $buf;
        }

        fclose($stream);

        return $data;
    }