How to transfer a file from Google Cloud Storage to Compute Engine instance using gcloud terminal?

时间:2017-08-13 13:46:47

标签: google-cloud-platform google-cloud-storage google-compute-engine

I would like to verify my website in Google Search Console by uploading a file to my website - example.com which is hosted on Google Cloud Compute Engine (Wordpress site deployed with Google Cloud Launcher) . It has to be placed on a website as example.com/123googlesearchconsoleexample.html , but I cannot upload it via Cloud Shell from a Google Cloud Storage bucket. Is there a way to do this?

I tried gcloud compute copy-files command

gcloud compute copy-files gs://example/123googlesearchconsoleexample.html example-prd-vm:~/

, but it seems that it does not work in the browser and this is how I would like to do it (without installing SDK). The error I get is:

(gcloud.compute.copy-files) All sources must be local files when destination is remote.

2 个答案:

答案 0 :(得分:6)

I don't know if there's a way of doing it in a single step, but it looks like it should be easy to do in two steps:

$ gsutil cp gs://example/123googlesearchconsoleexample.html .
$ gcloud compute copy-files 123googlesearchconsoleexample.html example-prd-vm:~/

The first command copies from Google Cloud Storage to the VM running Cloud Shell. The second command then copies from that VM to example-prd-vm... it's now copying a local file, so the error you're currently getting won't be applicable.

答案 1 :(得分:0)

首先使用以下命令列出您拥有的所有存储桶

gsutil ls

使用以下命令将文件从Google Cloud Storage存储桶下载到本地位置

gsutil cp gs://bucketname/filename local-location

您可以使用-r选项从GCS下载文件夹

gsutil cp -r gs://bucketname/folder-name local-location

您还可以使用-m选项下载大量文件,这些文件将执行并行(多线程/多处理)复制

gsutil -m cp -r gs://bucketname/folder-name local-location