本文介绍了如何将文件从Google计算引擎复制到本地目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令将文件从实例复制到本地目录

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

错误:(gcloud.compute.scp)[/usr/bin/scp]退出,返回码为[1].

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

从本地目录复制到GCE可以正常工作.

Copying from local directory to GCE works fine.

我还查看了斯坦福大学的教程和Google文档.

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

我有另外一个实例,那里没有这样的问题.

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

我有点相信SSH密钥可能有问题.

I somewhat believe it might be issue with SSH keys.

可能出了什么问题?

推荐答案

如果您的源路径和目标路径正确,则您的命令是正确的

将问题从Google Compute Engine虚拟机复制到本地计算机时,您在问题中发布的命令对我有用.

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

我还尝试了从另一端(即从本地计算机到GCE VM)进行复制,并且可以正常工作:

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依赖于PATH中存在的scp可执行文件.您提供给gcloud scp命令的参数将传递给scp二进制文件.假设您的源路径和目标路径正确,则应该可以.

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.

不过,根据您的特定错误消息,我看到仅当您尝试从中复制源路径是目录而不是文件时,才会出现变体.对于这种特殊情况,您可以传递--recurse参数(类似于常规scp支持的-r参数),该参数将递归复制指定目录下的所有文件和目录.

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

这篇关于如何将文件从Google计算引擎复制到本地目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:06