3

I would like to programmatically move a group of files from a local directory into a WebDAV directory.

I am guessing a simple batch file would not work because it is a WebDAV directory. Note: the machine is Windows Server 2003 so there is no support for mapping a WebDAV directory to a drive letter so the drive just looks like this: http://dev1:8080/data/xml and cannot be made to look like //dev1/data/xml

6 Answers 6

1

Cadaver may allow you to write a batch script that does all this; otherwise you could use CURL directly, but you'd need to know a bit more about the actual WebDAV protocol (you'd basically need to locally traverse a directory, MKCOL for every subdirectory and PUT for every file).

I'm not sure how well either of these tools compile on Windows, but if it doesn't work out of the box, you could always run it on top of Cygwin. While you're using Cygwin, you can also just create standard shell scripts (/bin/sh or /bin/bash) which will likely actually be easier than windows' .BAT format.

0

you could use the BMOVE Method

1
  • This is proprietary though. Standard WebDAV servers will not support it. Also; this would only work from moves within the WebDAV share. The OP wants to simply do a PUT.
    – Evert
    Aug 20, 2011 at 21:16
0

You could use a webdav client such as the one contained in this project (it's Apache Licensed afaik), then basically call it with a batch file / shell script

0

You can use python-webdav-library

from webdav import WebdavClient
url = 'https://somesite.net'
mydav = WebdavClient.CollectionStorer(url, validateResourceNames=False)
mydav.connection.addBasicAuthorization(<username>, <password>)

fid = open(<filepath of file you want to upload> ,'rb')
mydav.path = <path to where you want the file to be, ie '/a/b/c.txt'>
mydav.uploadFile(fid)
0

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

A sample WinSCP script to upload file over WebDAV:

open http://[email protected]/
put file.txt /path/
close

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

winscp.com /script=script.txt

You can also put everything on a single line:

winscp.com /command "open http://[email protected]/" ^
    "put file.txt /path/" "close"

If you really want to move (not copy) the files, add the -delete switch to the put command:

put -delete file.txt /path/

See an introduction to scripting with WinSCP.

(I'm the author of WinSCP)

0

Try the below code.

$filename = 'testing.text';

exec('curl --digest --user "' . $username . ':' . $password . '" -T "' . 
$filename . '" "https://sandbox.test.com/dav/content/" ');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.