python - 使用Python将zip文件从Google云存储上传到SFTP服务器,而不加载到内存中

标签 python google-cloud-storage sftp pysftp

我想将大型 zip 文件从 google 云存储桶上传到 SFTP 服务器,而不加载到内存和云功能中。 我正在使用 pysftp 进行 SFTP 传输。

with pysftp.Connection(host="SFTP Server", username='test', password='test', cnopts=cnopts) as sftp:
    sftp.cwd("/tmp")
    sftp.put("zip_file_from_google_bucket")

我们能否访问存储桶中文件的操作系统路径并在 sftp.put() 中提供文件路径,因为 gs:// 路径将无法被识别在 sftp.put() 中?

我们还有其他转账方式吗?

请指教。

最佳答案

首先,更好地使用Paramiko。 pysftp 已经死了。请参阅pysftp vs. Paramiko 。无论如何,以下内容都适用于 Paramiko 和 pysftp。


合并Paramiko SFTPClient.openGCS Blob.download_to_file :

client = storage.Client(credentials=credentials, project='myproject')
bucket = client.get_bucket('mybucket')
blob = bucket.blob('archive.zip')

with sftp.open('/sftp/path/archive.zip', mode="w+", bufsize=32768) as f:
    blob.download_to_file(f)

或者,合并 SFTPClient.putfoBlob.open .

with blob.open("rb") as f:
    sftp.putfo(f, '/sftp/path/archive.zip')

(未经测试,但至少应该给你这个想法)

关于python - 使用Python将zip文件从Google云存储上传到SFTP服务器,而不加载到内存中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73230723/

相关文章:

python - "shaded"matplotlib 中的水平条

python - matplotlib 散点图是否有 'levels' 等效参数?

python - 无法上传 > ~2GB 到 Google Cloud Storage

python - 编写 CSV 以存储在 Google Cloud Storage 中

c++ - 将 sftp 协议(protocol)与 libcurl 一起使用——如何列出目录的内容?

ssh - Windows 上的 VSFTPD 和其他问题

python - 在Python中将密码发送到sftp子进程

python - pyopenCL,openCL,无法在GPU上构建程序

python - Django "Unable to determine the file' s size“tempfile.TemporaryFile 错误

google-cloud-storage - 在 Google Compute Engine 中按标签计费