Esempio n. 1
0
function usage()
{
    print <<<EOD
This is an example allows you to put the contents of STDIN into a remote object
on Manta. It relies on your MANTA environment variables being set up correctly.

Usage:
 STDIN | mput.php <remote object path>

EOD;
}
if (count($argv) <= 1 || $argv[1] == 'help' || $argv[1] == '--help') {
    usage();
    exit(0);
}
/* Since we didn't specify any parameters to the constructor, we are pulling
 * all of our configuration from environment variables. */
$client = new MantaClient();
// Path to object
$path = $argv[1];
if (substr($path, 0, 2) == '~~') {
    $path = $client->getHomeDirectory() . substr($path, 2);
}
// Test if object is a directory
if ($client->isDirectory($path)) {
    fwrite(STDERR, "mput: cannot write object to directory path\n");
    exit(1);
}
// If you are doing this for real, use streams
$contents = file_get_contents('php://stdin', 'r');
$client->putObject($contents, $path);
Esempio n. 2
0
    print <<<EOD
This is an example allows you to get an object to STDOUT. It relies on your MANTA
environment variables being set up correctly.

Usage:
 mget.php <remote object path>

EOD;
}
if (count($argv) <= 1 || $argv[1] == 'help' || $argv[1] == '--help') {
    usage();
    exit(0);
}
/* Since we didn't specify any parameters to the constructor, we are pulling
 * all of our configuration from environment variables. */
$client = new MantaClient();
// Path to object
$path = $argv[1];
if (substr($path, 0, 2) == '~~') {
    $path = $client->getHomeDirectory() . substr($path, 2);
}
$stream = null;
$bufferSize = 1024;
try {
    $stream = $client->getObjectAsStream($path);
    // This is how we detect that a stream is referring to a directory
    if ($stream->getHeaders()['Content-Type'][0] == MantaClient::DIR_CONTENT_TYPE) {
        fwrite(STDERR, "mls: cannot get {$path}: This is a directory\n");
        exit(1);
    }
    // This is how you would read a stream
Esempio n. 3
0
    print <<<EOD
This is an example allows you to list directories. It relies on your MANTA
environment variables being set up correctly.

Usage:
 mls.php <remote path>

EOD;
}
if (count($argv) <= 1 || $argv[1] == 'help' || $argv[1] == '--help') {
    usage();
    exit(0);
}
/* Since we didn't specify any parameters to the constructor, we are pulling
 * all of our configuration from environment variables. */
$client = new MantaClient();
// Path to object or directory on Manta
$path = $argv[1];
if (substr($path, 0, 2) == '~~') {
    $path = $client->getHomeDirectory() . substr($path, 2);
}
try {
    // This lists a directory on Manta
    $contents = $client->listDirectory($path);
} catch (MantaException $e) {
    // This illustrates how you can trap on the HTTP error code.
    if ($e->getCode() == 404) {
        fwrite(STDERR, "mls: cannot access {$path}: No such file or directory\n");
        exit(1);
    }
    throw $e;