Command-line utility for WebDAV upload

2020-02-20 08:00发布

问题:

I need a command-line utility that can do WebDAV upload (HTTP PUT).

回答1:

cURL will do it for you.

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


回答2:

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



回答3:

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.



回答4:

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

Sample WinSCP script to upload a file over WebDAV:

open https://user@webdav.example.com/
put file.txt /path/
exit

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 https://user@webdav.example.com/" "put file.txt /path/" "exit"

Start with introduction to scripting with WinSCP.

You can even have WinSCP GUI generate the script file for you.

(I'm the author of WinSCP)



回答5:

Another option is "davix"

https://dmc.web.cern.ch/projects/davix/home

it has separated utils like davix-mkdir davix-put etc You can specify creditions in URL like

 davix-mkdir http://user:passw@example.com/dir_to_create
 davix-put local_file http://user:passw@example.com/dir_to_create/remote_file_name


回答6:

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.



回答7:

this overview contains a thourough list of webdav server and clients.

I'd opt for cadaver or, if my needs were very specific, a python script using the PyWebDAV library.



回答8:

Use KIO under KDE:

kioclient cp file.txt 'webdavs://user@webdav.example.com:443/'


回答9:

Teleric Fiddler has a "compose" tab where you can create your own customized WebDAV request. E.g. PROPFIND and OPTIONS etc.



标签: webdav