2017-07-04 2 views

Antwort

1

Erstellen Sie ein lokales Verzeichnis, um den Inhalt herunterzuladen.

DOWNLOAD_LOCATION_PATH = '/home/Desktop/s3' 

BUCKET_NAME = "xxxxxxxxxxxxxxxxx" 
AWS_ACCESS_KEY_ID= os.getenv("AWS_KEY_ID") # set your AWS_KEY_ID on your environment path 
AWS_ACCESS_SECRET_KEY = os.getenv("AWS_ACCESS_KEY") # set your AWS_ACCESS_KEY on your environment path 
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_ACCESS_SECRET_KEY) 
bucket = conn.get_bucket(BUCKET_NAME) 

erhalten Sie die Liste aller Dateien und Ordner in S3

bucket_list = bucket.list() 

Schleife durch jede Datei/Ordner, den Inhalt und im Download-Ordner

for l in bucket_list: 
     key_string = str(l.key) 
     s3_path = DOWNLOAD_LOCATION_PATH + key_string 
     try: 
      print ("Current File is ", s3_path) 
      l.get_contents_to_filename(s3_path) 
     except (OSError,S3ResponseError) as e: 
      pass 
      # check if the file has been downloaded locally 
      if not os.path.exists(s3_path): 
       try: 
        os.makedirs(s3_path) 
       except OSError as exc: 
        # let guard againts race conditions 
        import errno 
        if exc.errno != errno.EEXIST: 
         raise 
+0

bitte akzeptieren die Antwort erhalten mit wenn es Ihr Problem gelöst hat –

+0

Dies zeigt einen Fehler an: Traceback (letzter Anruf zuletzt): Datei "boto.py", Zeile 2, in Import Boto File "/home/R170610/boto.py", Zeile 8, in conn = boto.connect_s3 (access_key, secret_key) Attribute: 'Modul' Objekt hat kein Attribut 'connect_s3' – Ashima

+0

diese versuchen kann ebenso, >>> aus boto.s3.connection import S3Connection >>> conn = S3Connection ('', '') –

Verwandte Themen