【问题标题】:copy file/folder using scp command使用 scp 命令复制文件/文件夹
【发布时间】:2023-11-19 16:15:01
【问题描述】:

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

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

基本上,我正在尝试从 Windows 复制到 Linux。希望无论我是在 Windows 还是 Linux 上它都能正常工作。

【问题讨论】:

    标签: linux windows shell file-transfer scp


    【解决方案1】:

    我认为这不能以这种形式工作,带有反斜杠 \ 分隔符:

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

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

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

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

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

    更新

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

    • 安装Git。即使你不使用 Git,这个安装程序也包含一个出色的终端和常用的 *nix 命令,还有scp
    • 下载PuTTY。您可以使用pscp.exe 代替scp,上述语法将起作用。
    • 安装WinSCP。它有scripting features,但如果你想使用命令行,前两个选项更容易。

    【讨论】:

    • 如果我从 Windows 执行,我得到 'scp' 不是内部或外部命令、可运行程序或批处理文件。如果我从 Linux 到我的 Windows 机器,那么我会得到“ssh:连接到主机 端口 22:连接拒绝丢失连接”我想我必须使用 Winscp。
    • @knm 我更新了我的帖子,添加了一些选项来获取scp
    【解决方案2】:

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

    感谢和问候,
    阿洛克·萨克

    【讨论】:

      【解决方案3】:

      在 *nix 系统中,这应该可以工作:

      # to copy file.ext from remote server to current working directory
      # note the dot (.) at the end, which means current directory
      $ scp user@remote.server.com:~/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 user@remote.server.com:~/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 user@remote.server.com:~/dersired/folder .
      

      更多信息也可以在这篇文章中找到:scp command syntax

      【讨论】: