安装配置osscmd
在Linux或者Windows上下载SDK安装包后,解压缩后就可以使用 osscmd了。
使用时直接调用python osscmd即可获取相应的说明。每种命令有两种执行模式。以查询用户所创建的bucket为例子。执行的是gs命令,get service的简写。
$ python osscmd gs
can't get accessid/accesskey, setup use : config --id=accessid --key=accesskey
[backcolor=transparent]注意:如果出现这样的提示表明没有配置好ID和KEY,见步骤2中提示的配置命令。
$ python osscmd gs
2013-07-19 08:11 test-oss-sample
Bucket Number is: 1
$ python osscmd gs --id=your_id --key=your_key --host=your_endpoint
2013-07-19 08:11 test-oss-sample
Bucket Number is: 1
$python osscmd config --id=your_id --key=your_key --host=your_endpoint
$python osscmd getallbucket
$python osscmd createbucket mybucketname
$python osscmd getallbucket
$python osscmd list oss://mybucketname/
向bucket中上传一个object。假如本地文件名叫local_existed_file,其MD5值如下所示。
$ md5sum local_existed_file 7625e1adc3a4b129763d580ca0a78e44 local_existed_file
$ python osscmd put local_existed_file oss://mybucketname/test_object
[backcolor=transparent]提示: md5sum 为 Linux 命令, Windows 下无此命令。
$python osscmd list oss://mybucketname/
$ python osscmd get oss://mybucketname/test_object download_file
$ md5sum download_file
7625e1adc3a4b129763d580ca0a78e44 download_file
[backcolor=transparent]提示: md5sum 为 Linux 命令, Windows 下无此命令。
$ python osscmd delete oss://mybucketname/test_object
[backcolor=transparent]注意:如果bucket中还有object的话则这个bucket不能被删除。$ python osscmd deletebucket mybucketname
<LifecycleConfiguration>
<Rule>
<ID>1125</ID>
<Prefix>log_backup/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>2</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
python osscmd putlifecycle oss://mybucket lifecycle.xml
0.150(s) elapsed
python osscmd getlifecycle oss://mybucket
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
<Rule>
<ID>1125</ID>
<Prefix>log_backup/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>2</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
0.027(s) elapsed
python osscmd deletelifecycle oss://mybucket
0.139(s) elapsed
python osscmd getlifecycle oss://mybucket
Error Headers:
[('content-length', '288'), ('server', 'AliyunOSS'), ('connection', 'close'), ('x-oss-request-id', '54C74FEE5D7F6B24E5042630'), ('date', 'Tue, 27 Jan 2015 08:44:30 GMT'), ('content-type', 'application/xml')]
Error Body:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<BucketName>mybucket</BucketName>
<Code>NoSuchLifecycle</Code>
<Message>No Row found in Lifecycle Table.</Message>
<RequestId>54C74FEE5D7F6B24E5042630</RequestId>
<HostId>mybucket.oss-maque-hz-a.alibaba.net</HostId>
</Error>
Error Status:
404
getlifecycle Failed!
$osscmd putreferer oss://test --allow_empty_referer=true
0.004(s) elapsed
$osscmd getreferer oss://test
<?xml version="1.0" encoding="UTF-8"?>
<RefererConfiguration>
<AllowEmptyReferer>true</AllowEmptyReferer>
<RefererList />
</RefererConfiguration>
$osscmd putreferer oss://test --allow_empty_referer=false --referer='www.test.com'
0.092(s) elapsed
$osscmd getreferer oss://test
<?xml version="1.0" encoding="UTF-8"?>
<RefererConfiguration>
<AllowEmptyReferer>false</AllowEmptyReferer>
<RefererList>
<Referer>www.test.com</Referer>
</RefererList>
</RefererConfiguration>
$osscmd putreferer oss://test --allow_empty_referer=false --referer='www.test.com,www.test1.com'
$osscmd getreferer oss://test
<?xml version="1.0" encoding="UTF-8"?>
<RefererConfiguration>
<AllowEmptyReferer>false</AllowEmptyReferer>
<RefererList>
<Referer>www.test.com</Referer>
<Referer>www.test1.com</Referer>
</RefererList>
</RefererConfiguration>
$osscmd getlogging oss://mybucket
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。