[英]How to download all files from s3 bucket to local linux server while passing bucket and local folder value at runtime using python
我正在制作脚本从s3存储桶下载文件到本地linux文件夹。 为了实现这一点,我必须为我们想要下载内容的存储桶和文件夹使用动态值。
我知道怎么做
aws s3 cp s3://bucket /linux/local/folder --recursive --p alusta
但是如何在运行时接受桶值
dwn_cmd = "aws s3 cp s3://bucket/name/" + str(year_name) + '/' + str(month_name)
folder_path = "/local/linux/folder/" + folder_name
#subprocess.call(['aws','s3','cp',dwn_cmd,folder_path,'--recursive','--p', 'alusta'])
这显示子进程需要s3存储桶路径和本地文件夹路径的错误。 我认为它没有走上正轨。 如果我硬编码它正在工作的路径但不是这个。 我怎么能实现我的结果
同
dwn_cmd = "aws s3 cp s3://bucket/name/" + "2019" + '/' + "June"
folder_path = "/local/linux/folder/" + "test"
你会打电话
subprocess.call(['aws','s3','cp',
"aws s3 cp s3://bucket/name/2019/June",
"/local/linux/folder/test",
'--recursive', '--p', 'alusta']);
从dwn_command
删除aws s3 cp
参数:
dwn_cmd = "s3://bucket/name/" + "2019" + '/' + "June"
注意:不要使用subprocess.call([dwn_cmd,folder_path,' - recursive',' - p','alusta'])#wrong aws
和s3
之间的空格将被视为命令名称的一部分,所以它会在目录的子目录中查找命令,其中包含3个空格aws s3 cp s3:
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.