使用bash从S3下载私有文件

前端之家收集整理的这篇文章主要介绍了使用bash从S3下载私有文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图让以下bash脚本工作(从 http://curl.haxx.se/mail/archive-2014-10/0006.html#replies复制):
#!/bin/sh 
file=path/to/file 
bucket=your-bucket 
resource="/${bucket}/${file}" 
contentType="application/x-compressed-tar" 
dateValue="`date +'%a,%d %b %Y %H:%M:%S %z'`" 
stringToSign="GET 
${contentType} 
${dateValue} 
${resource}" 
s3Key=xxxxxxxxxxxxxxxxxxxx 
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary |      base64` 
curl -H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \ 
-H "Authorization: AWS ${s3Key}:${signature}" \ 
https://${bucket}.s3.amazonaws.com/${file}

无论我做什么,我都会收到SignatureDoesNotMatch错误.

任何关于如何解决这个问题的想法将不胜感激.

经过太多时间花在这上面我终于得到了它的工作:

这一行:

signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`

缺少’e’:

signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`

换句话说,在字符串签名之前,字符没有被转义.

另外,我还了解到,对于获取请求,内容类型毫无意义.

原文链接:https://www.f2er.com/bash/387150.html

猜你在找的Bash相关文章