Download file from a private bucket with cURL
This guide explains how to download a single file from a private Object Storage bucket using cURL and a bash script with Zerops object storage.
Prerequisites​
- Access to Zerops Object Storage
- Storage credentials (
ACCESS_KEY_ID
andSECRET_ACCESS_KEY
) - Bash environment
- OpenSSL and cURL installed
Caution
Store your storage credentials securely and never commit them to version control.
Script​
Save this script as download-storage.sh
:
#!/bin/bash
server="${3:-storage-prg1.zerops.io}"
file_path=$2
bucket=$1
set -eu pipefail
contentType="application/octet-stream"
dateValue=`date -R`
signature_string="GET\n\n${contentType}\n${dateValue}\n/${bucket}/${file_path}"
signature_hash=`echo -en ${signature_string} | openssl sha1 -hmac ${SECRET_ACCESS_KEY} -binary | base64`
curl -sSo ${file_path} \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${ACCESS_KEY_ID}:${signature_hash}" \
"https://${server}/${bucket}/${file_path}"
Usage​
- Make the script executable:
- Set your storage credentials as environment variables:
- Run the script:
Troubleshooting​
- Permission Denied: Check your
ACCESS_KEY_ID
andSECRET_ACCESS_KEY
- File Not Found: Verify bucket name and file path
- Script Error: Ensure the script has execute permissions