网站制作学习网Linux→正文:Shell curl 阿里云OSS 脚本
字体:

Shell curl 阿里云OSS 脚本

Linux 2018/7/8 11:46:17  点击:不统计

学习www.网for站asp制.cn作
 使用阿里云oss时,需要通过curl 上传文件,查询网络找到一个阿里云oss上传的shell,如下

------------------------开始线--------------------

#!/bin/sh
host=需要修改
bucket=需要修改
Id=需要修改
Key=需要修改
 
 
method=$1
source=$2
dest=$3
if test -z "$method"
then
    method=GET
fi
 
 
if [ "get" = ${method} ] || [ "GET" = ${method} ]
then
    method=GET
elif [ "put" = ${method} ] || [ "PUT" = ${method} ]
then
    method=PUT
else
    method=GET
fi
if test -z "$dest"
then
    dest=$source
fi
 
 
if test -z "$method" || test -z "$source" || test -z "$dest"
then
    echo $0 put localfile objectname
    echo $0 get objectname localfile
    exit -1
fi
 
 
if [ "put" = ${method} ] || [ "PUT" = ${method} ]
then
    resource="/${bucket}/${dest}"
    contentType=`file -ib ${source} |awk -F ";" '{print $1}'`
    dateValue="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`"
    stringToSign="${method}\n\n${contentType}\n${dateValue}\n${resource}"
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${Key} -binary | base64`
    url=http://${host}/${resource}
    echo "upload ${source} to ${url}"
    curl -i -q -X PUT -T "${source}" \
      -H "Host: ${host}" \
      -H "Date: ${dateValue}" \
      -H "Content-Type: ${contentType}" \
      -H "Authorization: OSS ${Id}:${signature}" \
      ${url}
else
    resource="/${bucket}/${source}"
    contentType=""
    dateValue="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`"
    stringToSign="${method}\n\n${contentType}\n${dateValue}\n${resource}"
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${Key} -binary | base64`
    url=http://${host}/${resource}
    echo "download ${url} to ${dest}"
    curl --create-dirs \
      -H "Host: ${host}" \
      -H "Date: ${dateValue}" \
      -H "Content-Type: ${contentType}" \
      -H "Authorization: OSS ${Id}:${signature}" \
      ${url} -o ${dest}
fi
-------------------------------------------结束线------------------------

原载于:http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
 

·上一篇:My oh zsh alias 配置 >>    ·下一篇:网站制作学习网
推荐文章
最新文章