# Copy file to WebDAV via Command Line on Windows 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.

-
Nothing simpler without using 3rd party software. User doesn't have to be logged in; but the batch file will run as a user, that user will get the mappings... – Chris S Aug 4 '11 at 15:02
In your question you state that the WebDAV folder is on the same server, but in response to my answer, you say that it is a different server. Please pick one and clarify. – gWaldo Sep 14 '11 at 12:13

Free WinSCP (for Windows) supports WebDAV (and WebDAVS) in the latest beta version (5.6 and later). 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

(I'm the author of WinSCP)

-

Why, oh why, (if it's on the same server) don't you copy from local folder to local folder?

copy c:\path\myfile.txt c:\path\to\www-root\subdir\destination\


You may need to restart IIS/Apache (or whatever) after the file is copied, but most likely not.

-
It's not on the same server, of course. – Boden Sep 6 '11 at 3:15
Don't you specify that it is in the same server in the original post? – gWaldo Sep 6 '11 at 15:03
If they are different servers in the same LAN, you can just do a normal net use x: \\server\share and then copy. – gWaldo Sep 6 '11 at 15:06
@gWaldo, you're assuming the WebDav is just serving a file directory. I know SharePoint in particular allows you to mount Sites as WebDav folders, but it's all stored in the DB. This might be something similar. – Chris S May 28 '12 at 14:42

You might try using pushd and popd, which help automate the mounting of the drive some. You also might try using PowerShell, if possible.

-

DavCopy is a command line tool to push files to WebDAV. It supports command line authentication for batch jobs, so it can run when you're not logged in.

The webclient service isn't needed to run the tool.

It uses simple syntax, too. similar to robocopy.

-