Skip to content

Use AWS CLI and s5cmd

AWS CLI is the official command-line tool and the most complete; s5cmd handles many files with high concurrency and is faster. Both can connect to S4 directly.

Prerequisites

AWS CLI

Install and configure

Install by following the official instructions, then create a separate profile for S4:

PowerShell
aws.exe configure set aws_access_key_id "Your AccessKey" --profile s4
aws.exe configure set aws_secret_access_key "Your SecretKey" --profile s4
aws.exe configure set region cn-east-1 --profile s4
aws.exe configure set endpoint_url https://s3.bitiful.net --profile s4
aws configure set aws_access_key_id "Your AccessKey" --profile s4
aws configure set aws_secret_access_key "Your SecretKey" --profile s4
aws configure set region cn-east-1 --profile s4
aws configure set endpoint_url https://s3.bitiful.net --profile s4
aws configure set aws_access_key_id "Your AccessKey" --profile s4
aws configure set aws_secret_access_key "Your SecretKey" --profile s4
aws configure set region cn-east-1 --profile s4
aws configure set endpoint_url https://s3.bitiful.net --profile s4

Putting endpoint_url in a profile requires AWS CLI 2.13 or later. With older versions, add --endpoint-url https://s3.bitiful.net to every command.

Add --profile s4 to all later commands, or set the environment variable first:

PowerShell
$env:AWS_PROFILE="s4"
export AWS_PROFILE=s4
export AWS_PROFILE=s4

On Windows, run the commands in PowerShell and replace D:\ in the examples with your own directory.

Upload and download

PowerShell
# Upload
aws.exe s3 cp D:\logo.png s3://my-bucket/images/logo.png

# Specify the type and browser cache
aws.exe s3 cp D:\app.js s3://my-bucket/static/app.js --content-type "application/javascript" --cache-control "max-age=86400"

# Upload an entire directory
aws.exe s3 cp D:\dist s3://my-bucket/site/ --recursive

# Upload images only
aws.exe s3 cp D:\assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws.exe s3 cp s3://my-bucket/images/logo.png D:\logo.png

# Back up a database and upload it
mysqldump.exe mydb --result-file=D:\backup\mydb.sql
aws.exe s3 cp D:\backup\mydb.sql s3://my-bucket/backup/mydb.sql

# Print to standard output
aws.exe s3 cp s3://my-bucket/notes/todo.txt -
# Upload
aws s3 cp ./logo.png s3://my-bucket/images/logo.png

# Specify the type and browser cache
aws s3 cp ./app.js s3://my-bucket/static/app.js --content-type "application/javascript" --cache-control "max-age=86400"

# Upload an entire directory
aws s3 cp ./dist s3://my-bucket/site/ --recursive

# Upload images only
aws s3 cp ./assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws s3 cp s3://my-bucket/images/logo.png ./logo.png

# Upload from standard input, or print to standard output
mysqldump mydb | gzip | aws s3 cp - s3://my-bucket/backup/mydb.sql.gz
aws s3 cp s3://my-bucket/notes/todo.txt -
# Upload
aws s3 cp ./logo.png s3://my-bucket/images/logo.png

# Specify the type and browser cache
aws s3 cp ./app.js s3://my-bucket/static/app.js --content-type "application/javascript" --cache-control "max-age=86400"

# Upload an entire directory
aws s3 cp ./dist s3://my-bucket/site/ --recursive

# Upload images only
aws s3 cp ./assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws s3 cp s3://my-bucket/images/logo.png ./logo.png

# Upload from standard input, or print to standard output
mysqldump mydb | gzip | aws s3 cp - s3://my-bucket/backup/mydb.sql.gz
aws s3 cp s3://my-bucket/notes/todo.txt -

Sync

PowerShell
# Upload only files that changed
aws.exe s3 sync D:\dist s3://my-bucket/site/

# Also delete extra files in the bucket; do a dry run with --dryrun first
aws.exe s3 sync D:\dist s3://my-bucket/site/ --delete --dryrun
aws.exe s3 sync D:\dist s3://my-bucket/site/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws.exe s3 sync D:\dist s3://my-bucket/site/ --size-only
# Upload only files that changed
aws s3 sync ./dist s3://my-bucket/site/

# Also delete extra files in the bucket; do a dry run with --dryrun first
aws s3 sync ./dist s3://my-bucket/site/ --delete --dryrun
aws s3 sync ./dist s3://my-bucket/site/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws s3 sync ./dist s3://my-bucket/site/ --size-only
# Upload only files that changed
aws s3 sync ./dist s3://my-bucket/site/

# Also delete extra files in the bucket; do a dry run with --dryrun first
aws s3 sync ./dist s3://my-bucket/site/ --delete --dryrun
aws s3 sync ./dist s3://my-bucket/site/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws s3 sync ./dist s3://my-bucket/site/ --size-only

View and delete

PowerShell
aws.exe s3 ls                                  # Buckets you can access
aws.exe s3 ls s3://my-bucket/images/           # One directory level
aws.exe s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws.exe s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws.exe s3api head-object --bucket my-bucket --key images/logo.png

aws.exe s3 rm s3://my-bucket/images/logo.png
aws.exe s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
aws s3 ls                                  # Buckets you can access
aws s3 ls s3://my-bucket/images/           # One directory level
aws s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws s3api head-object --bucket my-bucket --key images/logo.png

aws s3 rm s3://my-bucket/images/logo.png
aws s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
aws s3 ls                                  # Buckets you can access
aws s3 ls s3://my-bucket/images/           # One directory level
aws s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws s3api head-object --bucket my-bucket --key images/logo.png

aws s3 rm s3://my-bucket/images/logo.png
aws s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
PowerShell
aws.exe s3 presign s3://my-bucket/images/logo.png --expires-in 3600
aws s3 presign s3://my-bucket/images/logo.png --expires-in 3600
aws s3 presign s3://my-bucket/images/logo.png --expires-in 3600

The validity period is in seconds, up to 604800 (7 days). For presigned upload links and S4 extension parameters, see Presigned URLs.

Metadata and tags

PowerShell
# Change the type and cache headers without re-uploading
aws.exe s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws.exe s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws.exe s3api get-object-tagging --bucket my-bucket --key app.js
# Change the type and cache headers without re-uploading
aws s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws s3api get-object-tagging --bucket my-bucket --key app.js
# Change the type and cache headers without re-uploading
aws s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws s3api get-object-tagging --bucket my-bucket --key app.js

REPLACE replaces all metadata. Custom metadata you leave out is removed.

Move and conditional writes

PowerShell
# Native move, no data copied
aws.exe s3api copy-object --bucket my-bucket --key "new/photo.jpg" --copy-source "my-bucket/old/photo.jpg?move=true"

# Write only if the object does not exist
aws.exe s3api put-object --bucket my-bucket --key locks/job --body D:\job.txt --if-none-match "*"
# Native move, no data copied
aws s3api copy-object --bucket my-bucket --key "new/photo.jpg" --copy-source "my-bucket/old/photo.jpg?move=true"

# Write only if the object does not exist
aws s3api put-object --bucket my-bucket --key locks/job --body ./job.txt --if-none-match "*"
# Native move, no data copied
aws s3api copy-object --bucket my-bucket --key "new/photo.jpg" --copy-source "my-bucket/old/photo.jpg?move=true"

# Write only if the object does not exist
aws s3api put-object --bucket my-bucket --key locks/job --body ./job.txt --if-none-match "*"

aws s3 mv copies and then deletes, so use the move above for large files. See Move and rename objects. If the object already exists, the conditional write returns 412 PreconditionFailed. See Conditional requests. --if-none-match requires a recent AWS CLI.

Clean up incomplete multipart uploads

Interrupted multipart uploads keep occupying space:

PowerShell
aws.exe s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws.exe s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"
aws s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"
aws s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"

Adjust concurrency and part size

PowerShell
aws.exe configure set s3.max_concurrent_requests 20 --profile s4
aws.exe configure set s3.multipart_threshold 64MB --profile s4
aws.exe configure set s3.multipart_chunksize 64MB --profile s4
aws configure set s3.max_concurrent_requests 20 --profile s4
aws configure set s3.multipart_threshold 64MB --profile s4
aws configure set s3.multipart_chunksize 64MB --profile s4
aws configure set s3.max_concurrent_requests 20 --profile s4
aws configure set s3.multipart_threshold 64MB --profile s4
aws configure set s3.multipart_chunksize 64MB --profile s4

s5cmd

Install and configure

s5cmd suits large numbers of small files. Download it from the s5cmd releases page, or install it with a package manager:

scoop install s5cmd
brew install peak/tap/s5cmd
brew install peak/tap/s5cmd

Configure it with environment variables:

PowerShell
$env:AWS_ACCESS_KEY_ID="Your AccessKey"
$env:AWS_SECRET_ACCESS_KEY="Your SecretKey"
$env:AWS_REGION="cn-east-1"
$env:S3_ENDPOINT_URL="https://s3.bitiful.net"
export AWS_ACCESS_KEY_ID="Your AccessKey"
export AWS_SECRET_ACCESS_KEY="Your SecretKey"
export AWS_REGION=cn-east-1
export S3_ENDPOINT_URL=https://s3.bitiful.net
export AWS_ACCESS_KEY_ID="Your AccessKey"
export AWS_SECRET_ACCESS_KEY="Your SecretKey"
export AWS_REGION=cn-east-1
export S3_ENDPOINT_URL=https://s3.bitiful.net

Common commands

PowerShell
# List
s5cmd.exe ls s3://my-bucket/images/

# Upload a directory
s5cmd.exe cp 'D:\dist\*' s3://my-bucket/site/

# Download a directory
s5cmd.exe cp 's3://my-bucket/site/*' D:\dist\

# Sync
s5cmd.exe sync D:\dist\ s3://my-bucket/site/

# Batch delete
s5cmd.exe rm 's3://my-bucket/tmp/*'

# Calculate size
s5cmd.exe du --humanize 's3://my-bucket/site/*'

# View contents, upload from standard input
s5cmd.exe cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd.exe pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd.exe presign --expire 1h s3://my-bucket/images/logo.png
# List
s5cmd ls s3://my-bucket/images/

# Upload a directory
s5cmd cp './dist/*' s3://my-bucket/site/

# Download a directory
s5cmd cp 's3://my-bucket/site/*' ./dist/

# Sync
s5cmd sync ./dist/ s3://my-bucket/site/

# Batch delete
s5cmd rm 's3://my-bucket/tmp/*'

# Calculate size
s5cmd du --humanize 's3://my-bucket/site/*'

# View contents, upload from standard input
s5cmd cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd presign --expire 1h s3://my-bucket/images/logo.png
# List
s5cmd ls s3://my-bucket/images/

# Upload a directory
s5cmd cp './dist/*' s3://my-bucket/site/

# Download a directory
s5cmd cp 's3://my-bucket/site/*' ./dist/

# Sync
s5cmd sync ./dist/ s3://my-bucket/site/

# Batch delete
s5cmd rm 's3://my-bucket/tmp/*'

# Calculate size
s5cmd du --humanize 's3://my-bucket/site/*'

# View contents, upload from standard input
s5cmd cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd presign --expire 1h s3://my-bucket/images/logo.png

Write several commands to a file and run them concurrently, in no particular order:

Use / in local paths in this file, on Windows too, for example D:/backup/a.zip.

commands.txt
cp ./a.zip s3://my-bucket/backup/a.zip
cp ./b.zip s3://my-bucket/backup/b.zip
rm s3://my-bucket/tmp/old.txt
PowerShell
s5cmd.exe run commands.txt
s5cmd run commands.txt
s5cmd run commands.txt

Adjust concurrency:

PowerShell
s5cmd.exe --numworkers 64 cp 'D:\data\*' s3://my-bucket/data/
s5cmd --numworkers 64 cp './data/*' s3://my-bucket/data/
s5cmd --numworkers 64 cp './data/*' s3://my-bucket/data/

The default concurrency is 256, which can trigger the QPS limit; lower it when you see 429.

FAQ

Do I need to set output in aws configure?

No. When a script processes the result, add --output json or --output text to the command.

aws s3 mb returns 403

Sub-users cannot create buckets. Create buckets in the console.

aws s3 ls returns nothing

It only lists buckets the sub-user has been granted access to. Grant access first.

Could not connect to the endpoint URL

The endpoint is not set, so the request went to AWS. Check with aws configure list --profile s4, or add --endpoint-url to the command.

SignatureDoesNotMatch

Check whether the keys have extra spaces, whether the Region is cn-east-1, and whether the local clock is accurate.