To transfer files from a Google Compute Engine (GCE) instance to your local computer, use the gcloud compute scp command. This allows you to securely copy files over SSH.
Before using the command, make sure:
Install guide
Use this command to copy a file from your VM to your local machine:
gcloud compute scp INSTANCE_NAME:~/remote-file.txt ~/local-directory/
To copy a whole folder (and its contents), add the –recurse flag:
gcloud compute scp --recurse INSTANCE_NAME:~/remote-directory/ ~/local-directory/
This copies everything inside remote-directory to your local machine.
Here’s a real working example that copies .bashrc from a VM named vm1 to your local Documents folder:
gcloud compute scp vm1:~/.bashrc ~/Documents/
If the previous commands don’t work due to zone or other issues, try adding the –zone flag:
gcloud compute scp vm1:~/.bashrc ~/Documents/ –zone=us-central1-a
-> To avoid typing the zone every time, set a default:
gcloud config set compute/zone us-central1-a
Work with our skilled Cloud developers to accelerate your project and boost its performance.
Hire Cloud Developers