Skip to content

Instantly share code, notes, and snippets.

@vishwarajanand
Created June 6, 2024 10:25
Show Gist options
  • Save vishwarajanand/28b4911b682d8de0e03668ba07ad9f4f to your computer and use it in GitHub Desktop.
Save vishwarajanand/28b4911b682d8de0e03668ba07ad9f4f to your computer and use it in GitHub Desktop.
<?php
// https://github.com/googleapis/google-cloud-php/issues/7343
require __DIR__ . "/vendor/autoload.php";
use Google\Cloud\Storage\StorageClient;
function dbug($stream)
{
var_dump(is_resource($stream));
var_dump(get_resource_type($stream));
var_dump(stream_get_meta_data($stream));
}
$ssh = ssh2_connect('tty.sdf.org', 22);
if (!$ssh) {
die('Connection failed');
}
$username = 'vishwarajanand';
$password = 'XX SANITIZED XX';
if (!ssh2_auth_password($ssh, $username, $password)) {
die('Authentication failed');
}
$stream = ssh2_exec($ssh, "ls -al && exit 2");
if ($stream === false) {
die('Unable to execute command');
}
stream_set_blocking($stream, true);
$client = new StorageClient();
$bucket = $client->bucket('thebookclub');
dbug($stream);
echo "Test START".PHP_EOL;
$object = $bucket->upload($stream, [
'name' => 'ssh-output.txt',
'validate' => false,
]);
echo "Test END".PHP_EOL;
dbug($stream); // stream would be not available, because ssh streams are not seekable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment