Linux 使用 scp 命令复制文件/文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19945881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:19:53  来源:igfitidea点击:

copy file/folder using scp command

linuxwindowsshellfile-transferscp

提问by user_new

How can I copy a file/folder from windows to linux (putty), probably using scp command?

如何将文件/文件夹从 Windows 复制到 linux (putty),可能使用 scp 命令?

I used scp user@hostname(windows):c:\folder\filname user@hostname(Linux):/folder/filename(destination), but unfotunately I got an error.

我使用了 scp user@hostname(windows):c:\folder\filname user@hostname(Linux):/folder/filename(destination),但不幸的是我遇到了错误。

Basically, I am trying to copy from windows to Linux. Hope it works whether I am on windows or Linux.

基本上,我正在尝试从 Windows 复制到 Linux。希望它适用于我在 Windows 或 Linux 上。

采纳答案by janos

I don't think this can work in this form, with the backslash \separators:

我认为这不能以这种形式使用反斜杠\分隔符:

scp user@hotname:c:\folder\filname user@hostname:\folder\filename(destination)

First of all, the path separator in Linux is /instead of \, so this would be better:

首先,Linux 中的路径分隔符/不是\,所以这样会更好:

scp user@hotname:c:\folder\filname user@hostname:/folder/filename

Secondly, your command looks like as if you're running this command on a third PC, on machineC to copy files from machineA to machineB. If this is not the case and you are in fact on machineA copying files to machineB, then this would be better:

其次,您的命令看起来就像是在第三台 PC 上运行此命令,在机器 C 上将文件从机器 A 复制到机器 B。如果情况并非如此,并且您实际上是在机器 A 上将文件复制到机器 B,那么这样做会更好:

scp c:\folder\filname user@hostname:/folder/filename

UPDATE

更新

If you don't have the scpcommand in Windows, here are a few options:

如果您scp在 Windows 中没有该命令,这里有几个选项:

  • Install Git. Even if you don't use Git, this installer includes an excellent terminal and common *nix commands, and scptoo
  • Download PuTTY. You can use pscp.exeinstead of scp, the above syntax will work.
  • Install WinSCP. It has scripting features, but if you want to use the command line the previous two options are easier.
  • 安装Git。即使你不使用的Git,这个安装程序包括一个优秀的终端和普通的* nix的命令,scp
  • 下载腻子。您可以使用pscp.exe代替scp,上面的语法将起作用。
  • 安装WinSCP。它具有脚本功能,但如果您想使用命令行,前两个选项更容易。

回答by linux_fanatic

If you want to copy a file from windows to linux using scp you have to Winscp http://www.siteground.com/tutorials/ssh/ssh_winscp.htmthis link would be helpful.

如果你想使用 scp 将文件从 windows 复制到 linux,你必须 Winscp http://www.siteground.com/tutorials/ssh/ssh_winscp.htm这个链接会很有帮助。

Thanks & Regards,
Alok Thaker

感谢和问候,
Alok Thaker

回答by kmario23

In *nix systems, this should work:

在 *nix 系统中,这应该有效:

# to copy file.ext from remote server to current working directory
# note the dot (.) at the end, which means current directory
$ scp [email protected]:~/desired/folder/file.ext .

# to copy all files in a folder from remote server 
#                                to current directory
# note the dot (.) at the end, which means current directory
$ scp -r [email protected]:~/desired/folder/* .


# copy a folder and all its contents as it is from remote server 
#                                              to current directory
# note the dot (.) at the end, which means current directory
$ scp -r [email protected]:~/dersired/folder .

More information can also be found in this article: scp command syntax

更多信息也可以在这篇文章中找到:scp 命令语法