Skip to content

Instantly share code, notes, and snippets.

@JustinTimperio
Created November 4, 2020 19:23
Show Gist options
  • Save JustinTimperio/ae695eef5fda1f1590a685a017bbb5ec to your computer and use it in GitHub Desktop.
Save JustinTimperio/ae695eef5fda1f1590a685a017bbb5ec to your computer and use it in GitHub Desktop.
Download a File to Minio with Curl and Zero External Libraries or Programs
#!/usr/bin/env sh
# Example: ./download_minio.sh example.url.com username password bucket-name minio/path/to/file.txt.zst /download/path/to/file.txt.zst
if [ -z $1 ]; then
echo "You have NOT specified a MINIO URL!"
exit 1
fi
if [ -z $2 ]; then
echo "You have NOT specified a USERNAME!"
exit 1
fi
if [ -z $3 ]; then
echo "You have NOT specified a PASSWORD!"
exit 1
fi
if [ -z $4 ]; then
echo "You have NOT specified a BUCKET!"
exit 1
fi
if [ -z $5 ]; then
echo "You have NOT specified a MINIO FILE PATH!"
exit 1
fi
if [ -z $6 ]; then
echo "You have NOT specified a DOWNLOAD PATH!"
exit 1
fi
# User Minio Vars
URL=$1
USERNAME=$2
PASSWORD=$3
BUCKET=$4
MINIO_PATH="/${BUCKET}/$5"
OUT_FILE=$6
# Static Vars
DATE=$(date -R --utc)
CONTENT_TYPE='application/zstd'
SIG_STRING="GET\n\n${CONTENT_TYPE}\n${DATE}\n${MINIO_PATH}"
SIGNATURE=`echo -en ${SIG_STRING} | openssl sha1 -hmac ${PASSWORD} -binary | base64`
curl -o "${OUT_FILE}" \
-H "Host: $URL" \
-H "Date: ${DATE}" \
-H "Content-Type: ${CONTENT_TYPE}" \
-H "Authorization: AWS ${USERNAME}:${SIGNATURE}" \
https://$URL${MINIO_PATH}
@indianwhocodes
Copy link

I am getting an error on using this script:

./download-minio.sh 172.22.0.10:9000 <redacted> <redacted> asiatrip mygage/asiatrip/test-video.mp4 ./test.mp4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

@ndrwk
Copy link

ndrwk commented Sep 3, 2021

I am getting an error on using this script:

./download-minio.sh 172.22.0.10:9000 <redacted> <redacted> asiatrip mygage/asiatrip/test-video.mp4 ./test.mp4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

Change https to http in the string 56.

@serut
Copy link

serut commented Apr 15, 2024

@Lucas-Steinmann
Copy link

I got the following error:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><Key>

The problem was that my implementation of echo did not accept -en as arguments and instead printed them. My solution was to use bash, whose echo-implementation supports -en. To do this, just replace sh in the first line with bash. If you don't want/can't use bash, the better solution would be to switch from echo to printf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment