下载
我这里直接用阿里云ecs的centos64位服务器
[root@iZ23lynfsq4Z ~]# ll
total 8348
-rwxr-xr-x 1 root root 8540284 Sep 26 15:25 ossutil64
-rwxr-xr-x 1 root root 40 Oct 12 2016 test.sh
[root@iZ23lynfsq4Z ~]#
添加到环境变量
[root@iZ23lynfsq4Z ~]# cp -rf ossutil64 /usr/bin/ossutil
[root@iZ23lynfsq4Z ~]# ll /usr/bin/ossutil
-rwxr-xr-x 1 root root 8540284 Sep 26 15:39 /usr/bin/ossutil
[root@iZ23lynfsq4Z ~]#
配置
[root@iZ23lynfsq4Z ~]# ossutil config
该命令建立将一个配置文件,在其中存储配置信息。
请输入配置文件路径(默认为:/root/.ossutilconfig,回车将使用默认路径。若是用户设置为其它路径,在使用命令时须要将--config-file选项设置为该路径):
未输入配置文件路径,将使用默认配置文件:/root/.ossutilconfig。
对于下述配置,回车将跳过相关配置项的设置,配置项的具体含义,请使用"help config"命令查看。
请输入语言(CH/EN,默认为:CH,该配置项将在这次config命令成功结束后生效):
请输入endpoint:oss-cn-hangzhou.aliyuncs.com
请输入accessKeyID:aaa
请输入accessKeySecret:bbb
请输入stsToken:
查看oss中的Buckets
[root@iZ23lynfsq4Z ~]# ossutil ls
CreationTime Region StorageClass BucketName
2017-08-24 11:59:34 +0800 CST oss-cn-hangzhou Standard oss://testedet
Bucket Number is: 1
0.048281(s) elapsed
[root@iZ23lynfsq4Z ~]#
同步文件
[root@iZ23lynfsq4Z ~]# ossutil cp a/b/a.txt oss://testedet
Succeed: Total num: 1, size: 3. OK num: 1(upload 1 files).
0.125956(s) elapsed
[root@iZ23lynfsq4Z ~]#
指定目录
[root@iZ23lynfsq4Z ~]# ossutil cp -rf a/b/a.txt oss://testedet/a/b/
Succeed: Total num: 1, size: 3. OK num: 1(upload 1 files).
0.055649(s) elapsed
[root@iZ23lynfsq4Z ~]#
经过php同步
bash-4.1$ cat index.php
<?php
$str = 'cd /home/www && ossutil cp -rf a/b/a.txt oss://testedet/a/b/ > /dev/null 2>&1 &';
$res = system($str,$retval);
if($retval == 0){
echo 'success';
} else {
echo 'failed';
}
bash-4.1$