26

I'm trying to upload all files of type .flv to an S3 bucket using the AWS CLI from a Windows server 2008 command line.

I do this:

aws s3 sync . s3://MyBucket --exclude '*.png'

And it begins uploading .png files instead.

I'm trying to follow the documentation and it gives an example that reads:

Local directory contains 3 files:
MyFile1.txt
MyFile2.rtf
MyFile88.txt
'''
aws s3 sync . s3://MyBucket/MyFolder --exclude '*.txt'
upload: MyFile2.rtf to s3://MyBucket/MyFolder/MyFile2.rtf

So what am I doing wrong?

  • You may find that [AWS Tools for PowerShell](https://aws.amazon.com/powershell/) is a much less painful command line option for Windows users. – Anthony Neace May 27 '14 at 18:23
  • @HyperAnthony Now I need to learn PowerShell... See my other question http://stackoverflow.com/questions/23918359/uploading-all-files-of-a-specific-type-to-s3-with-powershell –  May 28 '14 at 17:39

1 Answers1

64

Use:

aws s3 sync . s3://MyBucket/ --exclude "*" --include "*.flv"

It excludes all files, then includes .flv files. The order of parameters is important.

You can also use:

aws s3 cp . s3://MyBucket/ --recursive --exclude "*" --include "*.flv"

The difference is that sync will not re-copy a file that already exists in the destination.

Mooseman
  • 18,763
  • 14
  • 70
  • 93
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • 1
    Note: `sync` will re-copy if the files are outdated. E.g., if you made a change to a file on your local, and did a sync, that file will get uploaded even if a file with the same name already exists in your destination bucket. – Sumiya Jan 30 '22 at 06:34
  • What if you want to include several file types, i.e. .txt and .tsv ? – Carmen Sandoval Jul 01 '22 at 05:33
  • 2
    @gaelgarcia You can add multiple `--include` parameters. See: [Use of Exclude and Include Filters — AWS CLI Command Reference](https://docs.aws.amazon.com/cli/latest/reference/s3/#use-of-exclude-and-include-filters) – John Rotenstein Jul 01 '22 at 07:28