GCP 将文件从我的本地计算机复制到 GCP Vm

GCP Copying File from my local Machine to GCP Vm

我正在将我的文件从本地计算机复制到 Google 虚拟机。

我目前正在使用本地计算机 SSH 连接访问 Google 虚拟机

命令如下:

gcloud compute scp ~/Desktop/testing.png  dms-2:~/testing --internal-ip --zone=us-west1-b

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    19  100    19    0     0   2100      0 --:--:-- --:--:-- --:--:--  2375
testing.png                                                                                                                                                               100%  133KB  19.1KB/s   00:06 

但是当我在我的 Google VM 上执行 ls 时,什么也没有出现:

s0p04bp@dms-2:~$ cd /usr/lib/testing/
s0p04bp@dms-2:/usr/lib/testing$ ls
s0p04bp@dms-2:/usr/lib/testing$ pwd
/usr/lib/testing
s0p04bp@dms-2:/usr/lib/testing$ 

不确定为什么它没有在我的 google VM 中显示?

您似乎正在将文件复制到错误的目录。

The tilde (~) is a Linux "shortcut" to denote a user's home directory. Thus tilde slash (~/) is the beginning of a path to a file or directory below the user's home directory.

发件人:https://twiki.org/cgi-bin/view/Wikilearn/TildeSlash

如果您希望 testing.png 出现在目录 /usr/lib/testing/ 中,以 /usr/lib/testing/testing.png 结尾,您应该将其复制到那里。对于 GCP 实例,我还会具体说明我连接的用户。

下一个示例将假设 /usr/lib/testing/ 文件夹存在于远程实例上并具有正确的权限。由于 /usr/lib 通常只能由 root 用户单独编辑。

gcloud compute scp ~/Desktop/testing.png  s0p04bp@dms-2:/usr/lib/testing/ --zone=us-west1-b

如果该文件夹不存在,您需要先创建它并赋予它正确的权限。

gcloud compute ssh s0p04bp@dms-2 zone=us-west1-b --command "sudo mkdir -p /usr/lib/testing && sudo chown s0p04bp:s0p04bp /usr/lib/testing"