I am using s3cmd to upload files to my S3 server. My problem is that when a directory on the server does not exist the upload fails. How can I tell s3cmd to create the folder if it does not exist? I am using PHP.
-
As far as i know s3 doesn't have folders. You just put everything in the bucket. – Sabeen Malik Jul 01 '11 at 21:26
-
1It does have folders http://imageshack.us/photo/my-images/838/capturefhw.png/ – John Jul 01 '11 at 21:35
-
Can you put the file like this: s3cmd put file.jpg s3://yo/folder/ – Colum Jul 01 '11 at 21:40
-
No, this fails because "folder" does not exist – John Jul 01 '11 at 21:54
-
1to help google find this question, if you try to include folder name in the "mb" command, you get the error "Expecting S3 URI with just the bucket name set instead of..." – Adam Rabung Mar 14 '14 at 14:56
3 Answers
I believe you should try something like s3cmd put file.jpg s3://bucket/folder/file.jpg
.
S3 doesn't have the concept of directories, the whole folder/file.jpg
is the file name. If using a GUI tool or something you delete the file.jpg from inside the folder, you will most probably see that the folder is gone too. The visual representation in terms of directories is for user convenience.

- 10,816
- 4
- 33
- 50
This is how to create a folder:
s3cmd put foobar s3://bucket_name/new_directory/
To verify:
s3cmd la

- 4,861
- 3
- 22
- 42

- 227
- 1
- 4
- 8
If you don't want to upload a file, you can copy the special $folder$ object that s3 tools create to mark folders:
s3cmd cp 's3://bucket/parent_$folder$' 's3://bucket/parent/child_$folder$'
which creates a "child" "folder".
It's less confusing to upload something in the child location instead:
s3cmd put dummy s3://bucket/parent/child/dummy
Hive seems to require that the full S3 path exist when creating an external table. That's why I am looking at this question :)

- 717
- 5
- 3