Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy files from google compute engine to local directory

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?

like image 253
oya163 Avatar asked Jul 08 '17 03:07

oya163


People also ask

How do I transfer from cloud to local?

You can copy files from the remote system to the local system using the gcloud command. To denote a file in Cloud Shell, prefix the file name with the string "cloudshell". To denote a local file, prefix the file name with the string "localhost" as shown below.


2 Answers

Your command is correct if your source and destination paths are correct

The command as you've posted in your question works for me when copying a file from the Google Compute Engine VM to my local machine.

$ gcloud compute scp vm1:~/.bashrc ~/Documents/
.bashrc                                          100% 3515     3.4KB/s   00:00

I also tried doing the copy from other side (i.e. from my local machine to GCE VM) and it works:

$ gcloud compute scp ~/Documents/.bashrc vm1:~/temp/
.bashrc                                          100% 3515     3.4KB/s   00:00

$ gcloud compute scp ~/Documents/.bashrc vm1:~/.bashrc-new
.bashrc                                          100% 3515     3.4KB/s   00:00

gcloud relies on the scp executable present in your PATH. The arguments you provide to the gcloud scp command are passed through to the scp binary. Assuming your source and destination paths are correct, it should work.

Recursive copying using scp

Based on your particular error message though, I've seen that variation only appear when the source path you're trying to copy from is a directory instead of file. For that particular case, you can pass a --recurse argument (similar to the -r argument supported by regular scp) which will recursively copy all files and directories under the specified directory.

gcloud compute scp --recurse SRC_PATH DEST_PATH

like image 117
Tuxdude Avatar answered Oct 07 '22 03:10

Tuxdude


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.

like image 34
Manish Kumar Jha Avatar answered Oct 07 '22 03:10

Manish Kumar Jha