Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

To upload a folder to Amazon S3 using s3cmd, you can use the put command with the --recursive option. This command will upload all files within the specified directory to the specified bucket. Here are the steps:

  1. Install s3cmd: If you haven't installed s3cmd yet, you can do so by running the following command on your Linux system:

    sudo apt-get install s3cmd
    
  2. Configure s3cmd: You need to configure s3cmd with your AWS access key and secret key. You can do this by running:

    s3cmd --configure
    
  3. Upload the folder: Use the put command with the --recursive option to upload the folder and all its contents to the specified bucket:

    s3cmd put --recursive /path/to/local/folder s3://bucket-name/path/to/folder/
    
    • /path/to/local/folder is the directory you want to upload.
    • s3://bucket-name/path/to/folder/ is the path in the bucket where you want to upload the folder.
  4. Optional flags: You can add additional flags to customize the upload process. For example:

    • --acl-public sets the permissions to public.
    • --add-header=Cache-Control:max-age=86400 sets the cache control header to 1 day.
    s3cmd put --recursive --acl-public --add-header=Cache-Control:max-age=86400 /path/to/local/folder s3://bucket-name/path/to/folder/
    

Example Usage

Here is an example of uploading a folder named dir1 from the local directory /home/user to the bucket my.bucket in the path /assets/dir1/:

s3cmd put --recursive --acl-public --add-header=Cache-Control:max-age=86400 /home/user/dir1 s3://my.bucket/assets/dir1/

Additional Tips

Troubleshooting