我正在使用 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)
Run Code Online (Sandbox Code Playgroud)
谢谢你!