[英]BAT script to copy files from Windows to remote Linux systems
Is there anyway to copy files from Windows machine to a remote Linux machine with a DOS command/other command-line tool (by specifying username and password in the command).无论如何使用DOS命令/其他命令行工具(通过在命令中指定用户名和密码)将文件从Windows机器复制到远程Linux机器。 I normally do this using WinSCP and would like to write a script (BAT) to automate this.
我通常使用 WinSCP 执行此操作,并想编写一个脚本 (BAT) 来自动执行此操作。
Download a copy of pscp.exe (the PuTTY scp companion).下载pscp.exe (PuTTY scp 伴侣)的副本。 If you have setup SSH keys on the Linux server, which you can do with PuTTY on Windows, you can setup password-less copy to Linux machines from Windows.
If you have setup SSH keys on the Linux server, which you can do with PuTTY on Windows, you can setup password-less copy to Linux machines from Windows.
WinSCP scripting command-line to upload a file is like:上传文件的WinSCP 脚本命令行如下:
winscp.com /command "open sftp://username@example.com/" "put d:\www\index.html" "exit"
See the guide to WinSCP scripting .请参阅WinSCP 脚本编写指南。
Easier is to use a Generate transfer code function to have WinSCP GUI generate a script (or even a complete batch file) for a transfer.更简单的是使用生成传输代码 function让 WinSCP GUI 为传输生成脚本(甚至是完整的批处理文件)。
Install cygwin and you can use scp, ssh etc just like you would on linux.安装 cygwin,您可以像在 linux 上一样使用 scp、ssh 等。 Besides, you can use ordinary bash scripts instead of crappy bat-files.
此外,您可以使用普通的 bash 脚本代替蹩脚的 bat 文件。
If anyone is looking to do this in 2022, Windows 10 now comes with scp.如果有人希望在 2022 年这样做,Windows 10 现在带有 scp。 You can do
你可以做
scp path/localfile.txt remote-user@host:/home/path scp path/localfile.txt remote-user@host:/home/path
or the recursive version for directories或目录的递归版本
scp -r localfolder remote-user@host:/home/path scp -r localfolder remote-user@host:/home/path
Of course with scp you'll run into issues if you have a large number of files.当然,使用 scp 如果您有大量文件,您会遇到问题。 It copies everything as opposed to only changed / new files only.
它复制所有内容,而不是仅复制更改/新文件。
Then you'll need a tool like rsync, which is available through WSL (windows subsystem linux).然后你需要一个像 rsync 这样的工具,它可以通过 WSL(windows 子系统 linux)获得。
rsync -r localfolder remote-user@host:/home/path rsync -r localfolder remote-user@host:/home/path
(I personally hesitate to install new tools for a job, hence my desire to stick with what's already available) (我个人犹豫是否为工作安装新工具,因此我希望坚持现有的工具)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.