I am trying to download all sample files from my s3 bucket in amazon ec2 via boto3 and python3 script to my local hard drive. Here is the script.
#downloading files from s3
import boto3
import sys
import os
import argparse
import threading
from botocore.client import Config
instance_id = "i-03e7f6391a0f523ee"
action = 'ON'
ec2 = boto3.client('ec2')
s3=boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
my_bucket=s3.Bucket('tkbucket32')
print("listing all files in bucket")
for s3_file in my_bucket.objects.all():
print(s3_file.key)
s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')
Currently there are following files in bucket
hello.txt myhomepage.html
Now I want them to be downloaded to
D:\folder1\folder2\folder3
I am running scripts in Windows 7. My problem is this line
s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')
Where do I specify the path of on local hard drive where I want to download these files?
Change this line:
s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')
to:
s3.meta.client.download_file('tkbucket32', 'hello.txt', 'D:\\folder1\\folder2\\folder3\\hello.txt')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.