共计 1742 个字符,预计需要花费 5 分钟才能阅读完成。
由于内部网络管控严格,服务器上进出网络很多限制导致很多比较有用的包不能上传或下载,当然方式还是有的,但是违规(︶^︶)。例如每次找网络组开通oss网络权限总是很慢,也不知道办没办好又或者是权限没设对。需要自己测试网络是否放行,奈何又不能装其他东西,只能用curl来试试了
curl调用oss脚本
#!/bin/sh
export LANG="en_US.UTF-8"
# oss endpoint地址
host="oss-cn-gz-csa-d01-a.inner.y.csair.com"
# bucket名称
bucket="oss-paas-test"
# 请输入自己的:AccessKey ID
Id="ggggggggg"
# 请输入自己的:AccessKey Secret
Key="gggggggg"
# 获取方法
# put: 上传
# get: 下载
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 -e "Usage:"
echo -e "\t$0 put localfile objectname"
echo -e "\t$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 ${contentType}
echo ${dateValue}
echo ${stringToSign}
echo ${signature}
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
正文完