Command-line utility for WebDAV upload
WebdavWebdav Problem Overview
I need a command-line utility that can do WebDAV upload (HTTP PUT).
Webdav Solutions
Solution 1 - Webdav
cURL will do it for you.
curl -T filetoput.xml http://www.url.com/filetoput.xml
Solution 2 - Webdav
Solution 3 - Webdav
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.
Solution 4 - Webdav
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.
Solution 5 - Webdav
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://us[email protected]/
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://[email protected]/" "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)
Solution 6 - Webdav
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:[email protected]/dir_to_create
davix-put local_file http://user:[email protected]/dir_to_create/remote_file_name
Solution 7 - Webdav
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.
Solution 8 - Webdav
Use KIO under KDE:
kioclient cp file.txt 'webdavs://[email protected]:443/'
Solution 9 - Webdav
Teleric Fiddler has a "compose" tab where you can create your own customized WebDAV request. E.g. PROPFIND and OPTIONS etc.
Solution 10 - Webdav
To do WebDAV recursive upload of an arbitrary directory structure (files inside folders inside folders, etc.), the tool Rclone worked for me.
Based on this answer on SuperUser, I was able to recursively copy a directory by doing the following:
- Configure the connection:
rclone config create my-remote webdav \ url https://my-webdav-server/my-dir/ \ vendor other \ user 'username' rclone config password pass 'mypasswd'
- Copy:
rclone copy /home/me/mydir my-remote:
Rclone offers a number of other modes of dealing with files, including sync
, which brings the remote in line with the local copy by removing remote files not present locally (in addition to copying local files across that do not exist remotely). See the subcommands of Rclone for more information.