如何将文件从 Google 云端复制到本地机器? (云Shell)

How to copy files from Google Cloud to local machine? (Cloud Shell)

我花了太多时间试图弄清楚如何将文件从分配的 Google 云 Shell VM 复制到我的本地计算机。云 shell 很棒,但拥有本地副本也很棒。

大部分时间都花在尝试让某种形式的 gcloud compute scp 起作用,类似于这种语法:

$ gcloud compute scp some-instance:~/littlefile.zip ~/

然而除了compute命令,还有alpha cloud-shell!

无效的方法:

me@mylocalhost:~$ gcloud alpha cloud-shell scp ~/littlefile.zip .
ERROR: (gcloud.alpha.cloud-shell.scp) argument (cloudshell|localhost):SRC: Bad value [/home/me/littlefile.zip]: must start with cloudshell: or localhost:

me@mylocalhost:~$ gcloud alpha cloud-shell scp cloudshell:~/littlefile.zip localhost:~/littlefile.zip
~/littlefile.zip: No such file or directory
ERROR: (gcloud.alpha.cloud-shell.scp) [/usr/bin/scp] exited with return code [1].

提及:How to copy files from google compute engine to local directory 以防其他人找到它但需要 Cloud Shell 命令。

冒着"answering my own question,"的风险其实我刚刚解决了! W00T!

有效的方法:

me@mylocalhost:~$ gcloud alpha cloud-shell scp cloudshell:littlefile.zip localhost:.
littlefile.zip            100%   16KB 253.1KB/s   00:00
me@mylocalhost:~$ gcloud alpha cloud-shell scp cloudshell:littlefile.zip localhost:littlefile.zip
littlefile.zip            100%   16KB 212.1KB/s   00:00
me@mylocalhost:~$ gcloud alpha cloud-shell scp cloudshell:~/adirectory/still-littlefile.zip localhost:.
still-littlefile.zip      100%   16KB 198.0KB/s   00:00