Reputation: 141
When I use format like
gcloud compute copy-files user@instance-1:/home/user/file \ /home/user/Desktop \ --zone europe-west1-b
it gives me error
no such file or directory as desktop
Upvotes: 11
Views: 47634
Reputation: 6193
This worked for me
Syntax :
gcloud compute scp <UserName>@<ServerName/InstanceName>:~/<FilePathFromInstance> <LocalSystemFilePath>
Upvotes: 3
Reputation: 632
I used this on Linux:
LOGNAME=<USERNAME> gcloud compute scp <USERNAME>@<INSTANCE_NAME>:<TARGET_PATH> <LOCAL_PATH> --project=<PROJECT_ID> --zone=<ZONE_ID>
Upvotes: 0
Reputation: 1
Another way for Windows users is using remote application such as MobaXterm. After SSH to your unix servers, you can easily download/upload files from/to servers via GUI.
Upvotes: 0
Reputation: 1
Landed up using google storage buckets to move large files between compute engine and workstations. Moved multiple GBs in a few seconds instead of hours trying to download individual files.
Upvotes: -2
Reputation: 2323
If you're connecting to the instance via https://console.cloud.google.com using SSH for Google Cloud Platform
, you can download a specific file via "Download file" from the Settings menu (accessible through the settings icon in upper right corner).
Upvotes: 27
Reputation: 3198
If you have a file on gcloud compute engine instance which you want to transfer to local machine or another instance, the best way is to upload the file to google cloud storage. Make the link public and download it. Follow these docs https://cloud.google.com/storage/docs/uploading-objects
Suppose you have a file example.zip
that you want to download.
First create a bucket in gcloud storage, suppose example10
.
You have multiple language options to upload a file. I'll be showing examples in Curl and Python.
To use Restful API on curl you first have to get a OAUTH2_TOKEN to access the cloud storage.
Then type this on Terminal
curl -X POST --data-binary @example.zip \
-H "Authorization: Bearer [OAUTH2_TOKEN]" \
-H "Content-Type: application/zip" \
"https://www.googleapis.com/upload/storage/v1/b/example10/o?uploadType=media&name=myexample.zip"
Now I'll be showing you an example using Python
Make sure that your instance has Full Access to all Cloud APIs if you don't want to use an OAUTH2_TOKEN. Then you can use python to upload the object.
Install python's google cloud storage client
pip install --upgrade google-cloud-storage
Then open the python command line by entering python
on terminal
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
upload_blob("example10", "example.zip", "myexample.zip")
You can find option to give Full Access to all Cloud APIs by clicking on instances's name and editing the details.
Upvotes: 2
Reputation: 156
This works for me - Mac OS X
gcloud compute scp username@vminstance:source-directory local-directory --zone instancezone
Before you have to set PATH correctly for using Google SDK.
PATH=/your-google-cloud-sdk-folder/bin:$PATH
Upvotes: 14