S3ToSFTP: Move multiple files from same S3 key to SFTP path

时光总嘲笑我的痴心妄想 提交于 2020-08-06 06:40:49

问题


Requirement: Move multiple files from the same S3 Key to SFTP

Below is the part of the code, I was able to achieve moving one file into SFTP location. If the s3_key location has more than 1 file example as below, I need to get both files from /path/output to SFTP Location

/path/output/abc.csv
/path/output/def.csv

Tried: But both files are not posted

Tried passing s3_key as '/path/output/*.csv'

Code

with sftp.open(sftp_path + key_name, 'wb') as f:
     s3_client.download_fileobj(s3_bucket,s3_key, f)

回答1:


See Boto3 to download all files from a S3 Bucket.

Except that instead of downloading the files to a local file:

client.download_file(bucket, k, dest_pathname)

... you will stream them to SFTP:

with sftp.open(sftp_path + file.get('Key'), 'wb', 32768) as f:
    client.download_file(bucket, k, f)

Note that this simple change does not handle "subfolders".

For the purpose of the 32768 argument, see Writing to a file on SFTP server opened using pysftp "open" method is slow.



来源:https://stackoverflow.com/questions/62805719/s3tosftp-move-multiple-files-from-same-s3-key-to-sftp-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!