import boto3
_BUCKET_NAME = 'Bucket_Name'
_PREFIX = 'data/'
ACCESS_KEY='*********************'
SECRET_KEY='**************************'
client = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
def ListFiles(client):
"""List files in specific S3 URL"""
response = client.list_objects(Bucket=_BUCKET_NAME, Prefix=_PREFIX)
for content in response.get('Contents', []):
yield content.get('Key')
file_list = ListFiles(client)
for file in file_list:
client.download_file('Bucket_Name',file,'C:/Users/UserName/Desktop/folder/')
Traceback (most recent call last):
File "", line 21, in client.download_file('Bucket_Name',file,'C:/Users/User/Desktop/folder')
File "C:\ProgramData\Anaconda3\lib\site-packages\boto3\s3\inject.py", line 172, in download_file extra_args=ExtraArgs, callback=Callback)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto3\s3\transfer.py", line 307, in download_file future.result()
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\futures.py", line 106, in result return self._coordinator.result()
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\futures.py", line 265, in result raise self._exception
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\tasks.py", line 126, in call return self._execute_main(kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\tasks.py", line 150, in _execute_main return_value = self._main(**kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\download.py", line 603, in _main osutil.rename_file(fileobj.name, final_filename)
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\utils.py", line 271, in rename_file rename_file(current_filename, new_filename)
File "C:\ProgramData\Anaconda3\lib\site-packages\s3transfer\compat.py", line 25, in rename_file os.remove(new_filename)
PermissionError: [WinError 5] Access is denied: 'C:/Users/User/Desktop/folder'