如何将文件从谷歌计算引擎复制到本地目录 [英] How to copy files from google compute engine to local directory

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

问题描述

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

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/:是一个目录

$USER/Documents/: Is a directory

错误:(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.

我也查看了斯坦福的教程和谷歌的文档.

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 VM 复制到我的本地计算机时,您在问题中发布的命令对我有用.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆