简体   繁体   English

将文件从 Windows 复制到远程 Linux 系统的 BAT 脚本

[英]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) 来自动执行此操作。

You could use the command line version of PuTTY , pscp.exe .您可以使用PuTTY的命令行版本pscp.exe

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.

相关问题 从Linux在远程Windows上运行bat文件 - Run bat file on remote Windows from Linux 将日志文件从linux服务器复制到Windows共享服务器的脚本 - Script to copy log files from linux server to windows shared server 如何将远程Windows上的文件复制到Linux计算机上的本地Linux? - How to copy files on remote Windows to local Linux on a Linux machine? 如何使用scp将文件从远程计算机(运行Linux)复制到Windows计算机? - How do I copy files from a remote computer (running Linux) to my Windows computer using scp? Python 将文件从 Linux 复制到 WINdows - Python copy files from Linux to WIndows 如何从Windows系统将文件从python脚本复制到任何其他远程服务器? - How do I copy files from windows system to any other remote server from python script? How ansible copy file from remote windows to remote linux without local copy and ssh install in windows - How ansible copy file from remote windows to remote linux without local copy and ssh install in windows 如何将文件从Windows便携式计算机复制到Linux远程服务器 - How to copy file from Windows laptop to Linux remote server 在没有Cygwin的情况下将文件从远程Windows计算机复制到Linux计算机 - Copy a file from remote Windows machine to Linux machine without Cygwin 使用staf将文件从linux复制到远程Windows机器 - Copy file from linux to remote windows machine using staf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM