Scripting‎ > ‎Linux shell‎ > ‎

Curl http commands examples with webdav

Thank you for visiting this page, this page has been update in another link Curl http commands with WebDAV

curl rename remote webdav file use case.

Webdav file renaming is useful, particular to large storage system, which you want to rename file without relocating files.

Here is an example using curl to rename remote file.

curl --verbose  --capath /etc/grid-security/certificates/ --key $X509_USER_PROXY   -E $X509_USER_PROXY -H "Destination:" -X MOVE

Webdav file exist check, http HEAD command
Instead of using -X HEAD, it's better to use -I --head
              (HTTP/FTP/FILE)  Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header
              of a document. When used on a FTP or FILE file, curl displays the file size and last modification time only.

curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -I --head "https://<webdavdoor>/aa/bb"

Webdav mkdir, http MKCOL command

curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -X MKCOL "https://<webdavdoor>/aa/bb"

A script to check and rename a file remotly via webdav door, with performance measurement. To use it for production, add few if

s0=`date +%s%N`
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -I --head "https://<webdavdoor>/aa/bb/test"
s1=`date +%s%N`
let s_gap=($s1-$s0)/1000000
echo "step 1:HEAD time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -I --head "https://<webdavdoor>/test"
s2=`date +%s%N`
let s_gap=($s2-$s1)/1000000
echo "step 2 HEAD time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -I --head "https://<webdavdoor>/aa/bb"
s3=`date +%s%N`
let s_gap=($s3-$s2)/1000000
echo "step 3 HEAD time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -I --head "https://<webdavdoor>/aa"
s4=`date +%s%N`
let s_gap=($s4-$s3)/1000000
echo "step 4 HEAD time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -X MKCOL "<webdavdoor>/aa"
s5=`date +%s%N`
let s_gap=($s5-$s4)/1000000
echo "step 5 MKCOL time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -X MKCOL "<webdavdoor>/aa/bb"
s6=`date +%s%N`
let s_gap=($s6-$s5)/1000000
echo "step 6 MKCOL time elapsed $s_gap ms"
curl --cacert /tmp/x509up_u501 --capath /etc/grid-security/certificates/ --key /tmp/x509up_u501 -E /tmp/x509up_u501 -H "Destination:https://<webdavdoor>/aa/bb/test" -X MOVE https://<webdavdoor>:2880/test
s7=`date +%s%N`
let s_gap=($s7-$s6)/1000000
echo "step 7 MOVE time elapsed $s_gap ms"
let s_gap=($s7-$s0)/1000000
echo "total time elapsed $s_gap ms"

For how to get curl work with webdav door using SSL, see another post " Curl use case for webdav access using SSL"

It is tested with dcache webdav service, should work with other webdav site.