Table of Contents
1 Install webdav
- This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
- For closing http, use firewall with awall.
- Use https or davs for SSL.
- WEBDAV_USERNAME is username and WEBDAV_PASSWORD is password for digest authentication.
#!/bin/shset -e[ -z “${WEBDAV_USERNAME}” ] && WEBDAV_USERNAME=admin[ -z “${WEBDAV_PASSWORD}” ] && WEBDAV_PASSWORD=webdavsudo apk add apache2-webdav apache2-utils apache2-sslsudo mkdir /var/lib/davsudo mkdir /usr/uploadssudo chown apache:apache /var/lib/davsudo chown apache:apache /usr/uploads# Create digest password file with expect command.sudo apk add expectexpect -c “set timeout -1spawn sudo htdigest -c /usr/user.passwd DAV-upload ${WEBDAV_USERNAME}expect “New password: “send “${WEBDAV_PASSWORD}n”expect “Re-type new password: “send “${WEBDAV_PASSWORD}n”expect eof”sudo rc-update add apache2sudo rc-service apache2 start
2 Access to webdav
Install davfs2 package for mounting davfs.
$ sudo sed -e ‘s;^#http(.*)/v3.6/community;http1/v3.6/community;g’ -i /etc/apk/repositories$ sudo apk update$ sudo apk add davfs2
Get SSL certificate from server.
$ WEBDAV_SERVER_FQDN=webdav-server.hiroom2.com$ openssl s_client -showcerts -connect “${WEBDAV_SERVER_FQDN}”:443 < /dev/null 2> /dev/null | openssl x509 -outform PEM | sudo tee /etc/davfs2/certs/”${WEBDAV_SERVER_FQDN}”.pem
Run “mount -t davfs”.
$ sudo mount -t davfs https://${WEBDAV_SERVER_FQDN}/uploads /mntPlease enter the username to authenticate with serverhttps://webdav-server.hiroom2.com/uploads or hit enter for none.admin Username: Please enter the password to authenticate user admin with serverhttps://webdav-server.hiroom2.com/uploads or hit enter for none. Password:
Write file via webdav.
$ echo hello | sudo tee /mnt/hello.txt
For updating written file immediately, unmount /mnt.
$ sudo umount /mnt
Written file can be read in /usr/uploads.
$ sudo cat /usr/uploads/hello.txthello