【问题标题】:How to download all files from s3 bucket to local linux server while passing bucket and local folder value at runtime using python如何在运行时使用 python 传递存储桶和本地文件夹值时将所有文件从 s3 存储桶下载到本地 linux 服务器
【发布时间】:2019-10-19 01:33:24
【问题描述】:

我正在制作脚本以将文件从 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 存储桶路径和本地文件夹路径的错误。我认为它没有走上正轨。如果我硬编码它正在工作的路径但不是这个。我怎样才能达到我的结果

【问题讨论】:

  • 对不起,我使用了标签..评论..但它不存在
  • 有人可以帮我吗..我被困在这里面了..

标签: linux python-3.x amazon-s3 subprocess


【解决方案1】:

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']) # 错误 awss3 之间的空格将被视为命令名称的一部分,因此它将在目录的子目录中查找命令,其中包含 3 个空格 aws s3 cp s3:

【讨论】:

    猜你喜欢
    • 2022-06-21
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    相关资源
    最近更新 更多