如何编写脚本将文件从 Unix 复制到 Windows?

发布于 2024-07-13 18:36:17 字数 47 浏览 6 评论 0原文

有没有办法制作一个脚本将文件从 Unix 驱动器复制到 Windows 驱动器?

Is there any way a script can be made that copies files from a Unix drive onto a Windows drive?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

昨迟人 2024-07-20 18:36:17

我一直使用安全副本(SCP)手动执行此操作。 SCP 已经安装在大多数 Unix 机器上。 在我的电脑上,我安装了 PuTTY 这是一个安全终端应用程序Windows 还包含一个安全复制实用程序。

当您从 Windows 命令行手动执行安全复制时,您将 Unix 用户名输入命令行命令中,但随后必须在提示符下输入密码,因此它是交互式的。 但我也考虑过通过脚本或批处理文件来完成此操作。 在这种情况下,您需要创建并安装适当机器上的私钥和公钥。 我创建了适当的密钥并将它们安装在 Windows 和 Unix 计算机上,然后再次手动执行 Windows 命令行安全复制,这次它没有询问我的密码。 所以这是您完成任务的一种方法。 不过,我确信还有很多其他方法。

I do it manually all the time using secure copy (SCP). SCP comes already installed on most Unix machines. On my PC, I installed PuTTY which is a secure terminal app for Windows and also contains a secure copy utility.

When you do the secure copy manually from the Windows command line, you put your Unix username into the command line command, but then you have to type in your password at the prompt, so it's interactive. But I've also thought about doing it from a script or a batch file. In that case, you will need to create and install private and public keys on the appropriate machines. I created the appropriate keys and installed them on both the Windows and Unix machines and then I manually performed the Windows command line secure copy again and it did not ask me for my password that time. So this is one way you can accomplish your task. I'm sure there are many other ways, though.

尾戒 2024-07-20 18:36:17

是的,只要执行脚本的操作系统可以从 Unix 驱动器读取数据并写入 Windows 驱动器。 由于这是标记为 vbscript 的,我假设您在 Windows 上运行,因此您可能需要查看类似 的内容这是为了访问 Windows 的 Unix 文件系统(尽管这是一个 Linux ext 驱动程序)。 然后它只是运行一个标准的复制功能来完成您的任务。

Yes, as long as the operating system the script is executing on can read from the Unix drive and write to the Windows drive. Since this is tagged vbscript, I'll assume you're running on Windows so you might want to look into something like this to get access to Unix filesystems for Windows (although that's a Linux ext driver). Then it's just running a standard copy function to complete your task.

挽清梦 2024-07-20 18:36:17

既然您有 Samba 标签,那么您是在谈论将网络共享从 Unix 计算机安装到 Windows 计算机上吗?

如果是这样,它就会被视为普通的网络驱动器,您将能够通过共享复制您拥有权限的任何内容。

Since you have a Samba tag, are you talking about mounting a network share from a Unix machine onto your Windows machine?

If so, it is just treated like a normal network drive and you would be able to copy anything that you had permissions via the share.

流心雨 2024-07-20 18:36:17

我会使用 expect 工具。

这是一个示例,如何将

  • /local/path/to/file

上传到

  • \\HOST\SHARE\remote\path\to\file

使用 域进行身份验证\user 使用密码password

expect <<<EOF
set timeout 10
spawn smbclient //HOST/SHARE "-Udomain\\user%password"
expect {
  "smb: \\\\\\\\>" {
    send "cd /remote/path/to\r"
    expect {
      "NT_STATUS_OBJECT_NAME_NOT_FOUND" {exit 1}
      "smb: *>"                         {
        set timeout -1
        send "put /local/path/to/file file\r"
        expect {
          "putting file " {
            expect "smb: *>" {exit 0}
          }
          "smb: *>" {exit 1}
        }
      }
    }
  }
}
# Timeout
exit 1
EOF

I would use expect tool.

Here is an example, how to upload

  • /local/path/to/file

to

  • \\HOST\SHARE\remote\path\to\file

authenticating with domain\user using password password:

expect <<<EOF
set timeout 10
spawn smbclient //HOST/SHARE "-Udomain\\user%password"
expect {
  "smb: \\\\\\\\>" {
    send "cd /remote/path/to\r"
    expect {
      "NT_STATUS_OBJECT_NAME_NOT_FOUND" {exit 1}
      "smb: *>"                         {
        set timeout -1
        send "put /local/path/to/file file\r"
        expect {
          "putting file " {
            expect "smb: *>" {exit 0}
          }
          "smb: *>" {exit 1}
        }
      }
    }
  }
}
# Timeout
exit 1
EOF
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文