Copy file to WebDAV via Command Line on Windows 2003

command-line-interfacewebdavwindows-server-2003

I need to copy a file from a Windows 2003 server to a WebDAV folder (on the same server, if it matters). This operation will be performed via a batch script executed via Scheduled Tasks. I've enabled the WebClient service on the server.

So far I've determined that I can do it like this:

net use x: http://host/path
copy c:\path\myfile.txt x:
net use x: /delete

1) Is there a simpler way than creating a temporary mapped drive? Will it work via a batch file when no user is logged in?

2) Is there anything I should know about enabling the WebClient service on my server? Previously it was disabled, which I assume is default.

Best Answer

Free WinSCP (for Windows) supports WebDAV (and WebDAVS). WinSCP supports scripting/command-line operations too.

Sample WinSCP script to upload file over WebDAV:

open http://user@webdav.example.com/
put file.txt /path/
close

Save the script to a file (e.g. script.txt) and run like:

winscp.com /script=script.txt

You can also put everything on a single line:

winscp.com /command "open http://user@webdav.example.com/" "put file.txt /path/" "close"

For introduction to scripting with WinSCP, see:
https://winscp.net/eng/docs/guide_automation

WinSCP GUI can generate a script template for you.

(I'm the author of WinSCP)