Command-line utility for WebDAV upload

The most commonly used command line HTTP utility seems to be cURL, which will do PUT with its -T option. You would need to understand quite a bit of the WebDAV protocol to do more than upload with it, though.


For unix (and Windows with Cygwin installed) you can use Cadaver


If you need to upload the entire directory instead of one file over WebDAV, you can use the following approach.

Imagine you have the following local folder you're going to upload over WebDAV.

local_folder_to_upload
│   test.txt
│   test1.txt    
│
└───nested_folder1
│   │   file1.txt
│   │   file2.txt
│   │
│   └───nested_folder2
│       │   file11.txt
│       │   file12.txt

1.First you need to create nested directories from your local folder (if you have them) on a server. Since WebDAV doesn't support recursive upload, you have to do this in separate step (if you were to use ftp - you would add --ftp-create-dirs flag to do this). To create those folders over WebDAV you need to use MKCOL method.

curl -X MKCOL 'http://your.server/uploads/nested_folder1' --user 'name:pwd'
curl -X MKCOL 'http://your.server/uploads/nested_folder1/nested_folder2' --user 'name:pwd'

Please note that you can't create them in one request according to the spec.

if a request to create collection /a/b/c/d/ is made, and /a/b/c/ does not exist, the request must fail.

2.Second you can utilize output of find shell command to upload it to your server using curl.

cd local_folder_to_upload && find . -exec curl -T {} 'http://your.server/uploads/{}' --user 'name:pwd' \;

Code above loop over all your files inside given directory (using find) and add the output (file name with relative path) to the placeholder {} in the url of your webserver. So it makes multiple requests (one per each file), and since all nested folders were created in advance - those requests shouldn't fail.

Hope it's helpful to someone.


cURL will do it for you.

curl -T filetoput.xml http://www.url.com/filetoput.xml

Tags:

Webdav