aws / aws/aws-cli

aws s3 cp --recursive copies single file as a directory with the same name

Open
#8,190 8 comments 1 reaction 0 assignees View on GitHub
bug p3 s3
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

### Describe the bug

I can use `aws s3 cp --recursive` to copy a single file from my server to my S3 bucket just fine. However, when I copy it back to the server using the same command in reverse, it creates an empty directory with the name of the file:

`-rwxr-xr-x 1 root e_w_3_rw 1.7M Sep 20 16:58 PXL_20230519_230305349.PORTRAIT.jpg`
becomes
`drwxrwsr-x 2 root e_w_3_rw 6 Sep 20 16:42 PXL_20230519_230305349.PORTRAIT.jpg`

### Expected Behavior

Just as `cp -r` copies files and directories as expected, `aws s3 cp --recursive` should also copy files or directories as expected. In any case, behavior should be the same whether copying locally to S3 or the reverse.

### Current Behavior

Current behavior is that single files are not copied, but an empty directory with the name of the file is created instead, yet no errors are reported when this happens either.

### Reproduction Steps

1. Prepare an S3 bucket
2. Prepare a local Linux system with aws-cli installed
3. Prepare a directory with some files in it
4. `aws s3 cp --recursive` a local file to S3 (this should work fine - verify the file exists in S3)
5. Delete the local file
6. `aws s3 cp --recursive` The same file from S3 back to the original path
7. Notice that there is an empty directory with the name of the file instead of the file.

### Possible Solution

Ideally, `aws s3 cp --recursive` would work for directories or for single files and should work bi-directionally.

### Additional Information/Context

This was tested with Wasabi, but I expect S3 vendor shouldn't matter in this case.

### CLI version used

aws-cli/2.13.20

### Environment details (OS name and version, etc.)

aws-cli/2.13.20 Python/3.11.5 Linux/x86_64.centos.7 prompt/off

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.