scp 语法问题

scp 语法问题

我正在尝试将 .tar 档案从远程服务器复制到我的电脑。

我想要复制的档案目录:

canserhan@embserv:~/tar_files/rtl_archive.tar

目的地:

serhan@serhan-Lenovo-B560:~/Documents$ 

我连接到远程服务器并使用以下命令:

canserhan@embserv:~/tar_files$ scp canserhan@embserv:~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$
Password:
ssh: serhan-Lenovo-B560: Name or service not known
lost connection
canserhan@embserv:~/tar_files$ 

我使用的 scp 语法肯定有问题。但是我搞不清楚。你能帮我吗?

谢谢。

答案1

通常,如果您想通过 scp 向远程服务器发送某些内容:

scp some_files.tar user@remoteHost:
scp some_files.tar user@remoteHost:Documents/newname.tar

但如果你想下载一些东西:

scp user@remoteHost:Documents/foo.tar ~/Desktop
scp user@remoteHost:/any/other/dir/foo.tar .

答案2

来自 scp 手册页:

 -3      Copies between two remote hosts are transferred through the local
         host.  Without this option the data is copied directly between
         the two remote hosts.  Note that this option disables the
         progress meter.

我认为问题在于您的机器embserv无法“看到”您的另一台机器serhan-Lenovo-B560,或者,如果可以,它也无法解析名称。

当你使用两台远程机器调用 scp 时,它实际上会尝试做一些事情喜欢这:

ssh canserhan@embserv "scp ~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$"

这是一件好事,因为这意味着复制将更有效率,但它要求从机器 A 到机器 B 的 scp 能够正常工作,而这并不总是可行的。

如果是这个问题,您可以通过使用 来解决-3,或者通过传递 的数字 IP 地址serhan-Lenovo-B560(如果名称是问题),或者通过修复 ssh 设置embserv以便它可以访问 来解决serhan-Lenovo-B560

编辑:

那么,尝试一下这个:

scp canserhan@embserv:~/tar_files/rtl_archive.tar [email protected]:~Documents$

xxx.xxx.xxx.xx您的服务器的 IP 地址在哪里。

或者,如果失败了,这个肯定可以工作,但运行速度会更慢:

scp -3 canserhan@embserv:~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$

顺便说一句,~Documents$看起来也是错的。你确定不应该这样吗~/Documents

答案3

尝试以下命令:

scp ~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~/Documents/

embserv是您的本地计算机。如果您写下scp server1:/path/to/file server2:/path/to/second/file此内容,则指示scp将文件从一台服务器复制到第二台服务器。如果您想将本地文件复制到服务器或反之,只需跳过冒号:和计算机名称。此外,~在您的情况下,后面必须跟一个斜线。~转换为/home/username/

答案4

我相信你的网络没有 DNS。它似乎无法解析你的名字serhan-Lenovo-B560

您可以尝试一件事,只需输入远程端的IP。

$ scp canserhan@embserv:~/tar_files/rtl_archive.tar serhan@<remote-ip>:~Documents

此外,尝试提供完整/绝对路径而不是~

相关内容