How to copy files from google compute engine to local directory

Viewed 77463

I am trying to copy files from my instance to my local directory using following command

gcloud compute scp <instance-name>:~/<file-name> ~/Documents/

However, it is showing error as mentioned below

$USER/Documents/: Is a directory

ERROR: (gcloud.compute.scp) [/usr/bin/scp] exited with return code [1].

Copying from local directory to GCE works fine.

I have checked Stanford's tutorial and Google's documentation as well.

I have one another instance where there is no issue like this.

I somewhat believe it might be issue with SSH keys.

What might have gone wrong?

9 Answers

To copy files from VM to your desktop you can simply SSH into the VM and on top right corner there is a settings button, there you will find the download file option just enter the path of file.

If it is folder then first zip the folder then download it.

If you need to pass the information of zone, project name you may like to do as it worked for me: the instance name is the name you chose in the GCP instances.

gcloud beta compute scp --project "project_name" --zone "zone_name" instance_name:~jupyter/file_name /home/Downloads

I met the same problem. The point is you should run the scp command from a local terminal, rather than cloud terminal.

For copying file to local machine from Ubuntu vmware

For ex: you have instance by name : bhk

Run a basic nginx server and copy all the files in
/var/www/html (nginx serving dir)
and then from your local machine simple run
wget <vm's IP>/<your file path>

For example If my vm's IP is 1.2.3.4 and I want to copy /home/me/myFolder/myFile , then simply copy this file in /var/www/html

then run wget 1.2.3.4/myfile

this works for me:

gcloud compute scp --project "my-project" ./my-file.zip user@instance-1:~

--project - google cloud project name

my-file.zip - local file to send to VM

user - vm linux username

instance-1 - instance name (vm name)

~ - instance destination path

I use below script to upload directory from local to remote directory

gcloud compute scp --recurse myweb-app/www/* user@instant-name:/var/www/html/sub-sites/myweb-app/www/
Related