I want to copy a file from AWS S3 to SFTP server without downloading to local using python,any help on this can be appreciated, thank you.
Sample python code to run.
I want to copy a file from AWS S3 to SFTP server without downloading to local using python,any help on this can be appreciated, thank you.
Sample python code to run.
2
Answers
There is no command in Amazon S3 to ‘send’ a file to a destination. It is only possible to ‘download’ (or ‘read’) the contents of a file.
Therefore, the only way to accomplish your goal is to download the file from S3, then upload to the SFTP server.
You could take advantage of the features of smart-open ยท PyPI, which lets you ‘open’ a file on S3 or SFTP as if it were a local file, but please note this would still involve ‘downloading’ and ‘uploading’ in the contents of the file.
You will need to download the file from S3, then upload it to the SFTP server. That said, you do not need to download the file to your local machine’s drive, you can transfer down the data and immediately send it along to S3.
So, you can use boto3 to download the file, then use paramiko to send the file back up to the SFTP server. Since boto3 can return a file object, and paramiko can use a file object to upload, it’s mostly a matter of creating the connections and putting them together.