我正在使用Paramiko访问远程SFTP文件夹,并尝试编写代码将文件从SFTP路径传输到AWS S3存储桶(使用文件元数据的简单逻辑来检查其最后修改日期)。
我已经使用Boto3设置了与S3的连接,但似乎仍无法编写可直接传输文件而不首先下载到本地目录的工作代码。以下是我尝试使用Paramiko的getfo()
方法的一些代码,但它不起作用。
for f in files:
# get last modified from file metadata
last_modified = sftp.stat(remote_path + f).st_mtime
last_modified_date = datetime.fromtimestamp(last_modified).date()
if last_modified_date > date_limit: # check limit
print('getting ' + f)
full_path = f"{folder_path}{f}"
fo = sftp.getfo(remote_path + f,f)
s3_conn.put_object(Body=fo,Bucket=s3_bucket, Key=full_path)
谢谢!