简体   繁体   English

使用没有文件夹路径的cli上传到aws s3

[英]Upload to aws s3 using cli without folder path

I'd like to upload a file.txt on aws s3 that is located in something like main/part1/part2/file.txt , where part1 and part2 are unknown (those folders always change).我想在 aws s3 上上传一个file.txt ,它位于main/part1/part2/file.txt类的地方,其中part1part2是未知的(这些文件夹总是会改变)。 I can do that with the command aws s3 cp./main s3://mybucket --exclude "*" --include "*.txt" --recursive , but then in my bucket I have the file located in part1/part2/file.txt .我可以使用命令aws s3 cp./main s3://mybucket --exclude "*" --include "*.txt" --recursive来做到这一点,但是在我的存储桶中,我的文件位于part1/part2/file.txt I'd like file.txt to be at the base of the bucket, not inside part1/part2我希望file.txt位于存储桶的底部,而不是在part1/part2

Is that possible given that part1 and part2 are constantly changing? part1部分和part2部分不断变化,这可能吗?

for dir1 in $(ls main); do
    for dir2 in $(ls main/$dir1); do
        aws s3 cp ./main/$dir1/$dir2/ s3://my-bucket --exclude "*" --include "*.txt" --recursive
    done
done
upload: main/part1/part2/file.txt to s3://my-bucket/file.txt
upload: main/part11/part22/file2.txt to s3://my-bucket/file2.txt

The following will work if main will never contain more than 1 subdirectory at a time ( part1 ) & that subdirectory in-turn will never contain more than 1 subdirectory at a time ( part2 ):如果main一次永远不会包含超过 1 个子目录( part1 )并且该子目录一次永远不会包含超过 1 个子目录( part2 ),则以下将起作用:

aws s3 cp ./main/*/*/ s3://my-bucket --exclude "*" --include "*.txt" --recursive
upload: main/part1/part2/file.txt to s3://my-bucket/file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM