使用Cloud Functions将文件从Google Cloud Storage传输到Windows VM实例

席德

我正在尝试设置一个Cloud Function,该功能将文件存储桶中的文件移动和删除到同一项目的Windows实例中。当然,如果我们从实例在本地运行它并使用gsutil,就可以使其正常运行。

但是,我们如何在本地文件夹位置的云功能脚本中对VM路径进行编码?

我还共享了VM内的本地文件夹。

非常感谢您的投入。

下面是代码,

import logging
from google.cloud import storage
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="serviceaccount.json"

#logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) 
bucket_name = 'bucket name'
#File_name = 'filename'
# Instance/VM location where the files should be downloaded into (VM NAME)
folder = '//VW123456789/Cloud-Files' 

storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blobs = bucket.list_blobs() #List all objects that satisfy the filter.

# Download the files inside windows-VM on GCP 
def download_to_local():
 logging.info('File download Started...Please wait for the job to complete!')
 # Create this folder locally if not exists
 if not os.path.exists(folder):
    os.makedirs(folder)
 # Iterating through for loop one by one using API call
 for blob in blobs:
    logging.info('Blobs: {}'.format(blob.name))
    destination_files = '{}/{}'.format(folder, blob.name) 
    blob.download_to_filename(destination_files)
    logging.info('Exported {} to {}'.format(blob.name, destination_files))
    blob.delete()
if __name__ == '__main__':
 download_to_local()

谢谢!

约翰·汉利

有几种方法可以将文件复制到Windows服务器或从Windows服务器复制文件。这些方法都不容易在Cloud Function中实现。

Windows CIFS文件共享

此方法涉及启用Windows共享。AFAIK没有简单的SAMBA客户端可以在Cloud Functions中实现。

SFTP

此方法需要为客户端设置Windows Server SSH服务器和SSH密钥对(云功能)。有一些Python SSH客户端库(paramiko)可以与Cloud Functions一起使用。通过paramiko可以轻松实现使用SFTP传输文件。

REST API服务器

此方法需要创建自己的软件,该软件提供REST API(或类似技术),Cloud Functions可以通过HTTPS调用该API。您将需要管理授权。实现自己的API和安全性会带来巨大的风险。

建议

云功能是与Windows Server连接的错误服务。我建议在调用的Windows Server而不是Cloud Function上创建HTTP端点。现在,您已从设计方程式中删除了Windows Server授权。您的Python代码可以直接在与Cloud Storage连接的Windows上运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将文件从 URL 传输到 Cloud Storage

将大文件从Google BigQuery传输到Google Cloud Storage

以编程方式将文件从Azure Blob存储传输到Google Cloud Storage

如何使用Google Cloud Function将文件从Cloud Storage存储桶中推送到实例中?

如何使用带有 Python 的 Google Cloud Functions 将列表写入 Google Cloud Storage 中的文件

使用外部IP访问Google Cloud VM实例Tomcat

通过Node / Express服务器将大文件(2GB +)流式传输到Google Cloud Storage存储桶

使用 Google Cloud Functions 将 [keys] SSH 到 VM

如何通过Cloud Functions将文件上传到Cloud Storage并使用Firestore控制对Cloud Storage的访问?

如何使用 Cloud Scheduler 启动 VM 实例

从Google Cloud Storage流式传输文件

Google Cloud VM实例如何开启IP转发

如何防止Google Cloud Dataproc群集VM实例自动关闭?

Google Cloud 不断执行程序 vm 实例

无法连接到 Google Cloud VM 实例上的 SSH

从在Google Cloud VM实例上运行的应用程序访问Google Secrets-将Cloud API分配给VM

使用Google Cloud Dataflow合并Google Cloud Storage中的文件

无法使用python通过TCP连接到我的Google Cloud VM实例

如何在Google Cloud Platform中的两个VM实例之间使用磁盘

使用后缀的Google Cloud Computing实例VM上的Amazon SES

Google Cloud Platform:如何监视VM实例的内存使用情况

无法使用Google Cloud Storage和Cloud Functions for Firebase下载文件

将文件从Firebase Cloud Functions上传到Cloud Storage

如何使用Deployment Manager将文件写入Google Cloud Storage?

使用Flask将文件上传到Google Cloud Storage

使用 Codeigniter 将文件上传到 Google Cloud Storage

使用 For 循环将多个文件上传到 Google Cloud Storage

如何使用Google Cloud Dataflow将压缩文件写入Google Cloud Storage?

使用Google DataFlow对直接将数据流式传输到Cloud SQL的简单查询