BAT script to copy files from Windows to remote Linux systems
Asked Answered
S

5

9

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). I normally do this using WinSCP and would like to write a script (BAT) to automate this.

Solitta answered 28/5, 2011 at 14:55 Comment(1)
WinSCP can be run from scripts.Fragmentary
M
7

You could use the command line version of PuTTY, pscp.exe.

Meingolda answered 28/5, 2011 at 14:58 Comment(1)
Technically pscp.exe isn't a command line version of PuTTY, only the secure-copy component. plink.exe is the command line companion to PuTTY, though it is designed for remote commands without launching a shell.Kellikellia
G
6

WinSCP scripting command-line to upload a file is like:

winscp.com /command "open sftp://[email protected]/" "put d:\www\index.html" "exit"

See the guide to WinSCP scripting.


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.

Generate transfer code dialog

Gizela answered 13/6, 2014 at 8:4 Comment(1)
Ty, for update about generate transfer function. This is actually where I planned to start at, and wasn't sure if it exists :)Ashwell
K
5

Download a copy of pscp.exe (the PuTTY scp companion). 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.

Kellikellia answered 28/5, 2011 at 14:59 Comment(0)
R
1

Install cygwin and you can use scp, ssh etc just like you would on linux. Besides, you can use ordinary bash scripts instead of crappy bat-files.

Roundhouse answered 28/5, 2011 at 14:58 Comment(0)
G
1

If anyone is looking to do this in 2022, Windows 10 now comes with scp. You can do

scp path/localfile.txt remote-user@host:/home/path

or the recursive version for directories

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. 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 -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)

Gabor answered 11/2, 2022 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.