Copy files from remote server to Google Cloud Cloud

How to copy files from remote server to google bucket? For example,

gcloud compute scp username@server:/path/to/file gs://my-bucket

This method gives an error: All sources must be local files when destination is remote.

Also, gsutil only provides support for cp, not scp.

Thanks in advance!

+3


source to share


2 answers


You can also directly execute the command gsutil

on your GCE VM (most VM images have the cloud SDK pre-installed). For example:

gcloud compute ssh user@server --zone my_zone \
  --command='gsutil cp path/to/my_file gs://MY_BUCKET'

      

Note that for this to work, your service account associated with the VM must have an appropriate scope for GCS. If you run



gcloud beta compute instances describe my_instance --zone my_zone \
  --format="value(serviceAccounts.scopes)"

      

It will display a list of scopes set for the VM service account. Make sure you have https://www.googleapis.com/auth/cloud-platform

either https://www.googleapis.com/auth/devstorage.full_control

or https://www.googleapis.com/auth/devstorage.read_write

. If not, you can use the set-scopes beta command to reset, or go to the console and edit the VM.

+3


source


gsutil supports streaming data, so you can try to bind the data.

Not 100% sure if this works with arbitrary binary data (and I'm on a phone so I can't test it)



gcloud compute ssh username@server --command='cat /path/to/file' | gsutil cp - gs://my-bucket

      

-1


source







All Articles