HostOnNet Blog

Uploading files to Amazon s3 with s3cmd

Looking for Linux Server Admin or WordPress Expert? We can help.

s3cmd allows you to upload files and folders to Amazon S3 or sites that support Amazon S3 API for example www.s3for.me

Installing s3cmd

You can download latest version of s3cmd from

https://github.com/s3tools/s3cmd/releases/

To install version 2.0.0 (latest at the time of writing this post), run

cd /usr/local/src
wget https://github.com/s3tools/s3cmd/releases/download/v2.0.0/s3cmd-2.0.0.tar.gz
tar xf s3cmd-2.0.0.tar.gz 
cd s3cmd-2.0.0
python setup.py install

s3cmd is python 2 program, won’t work with python 3.

Syncing all files on local folder to Amazon s3

To sync all files in local folder to amazon s3 bucket, run

s3cmd sync -v /path/to/local/folder/ s3://bucket-name/

s3cmd sync work like rsync.

Setting Permission for all files in a bucket

To make all files in a bucket public, run

s3cmd setacl --acl-public --recursive -v s3://bucket-name/

To make all files in a bucket private

s3cmd setacl --acl-private --recursive -v s3://bucket-name/

List All files in a s3 bucket

s3cmd ls -r s3://bucket-name/

If you only want file names, then use awk

s3cmd ls -r s3://bucket-name/ | awk '{print $4}'

Posted in Cloud

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.