Davfs2 allows you to access resources on a remote server like it would be a local disk, in this case nextcloud.
Install and configure davfs2
sudo apt-get install davfs2
Add yourself to davfs group:
sudo usermod -aG davfs2 <username>
Create a directory, and mount it:
mkdir ~/nextcloud sudo mount -t davfs https://files.newro.co/remote.php/dav/files/<username>/ ~/nextcloud
After the mount you will be prompted for your username and password from nextcloud.
If you want to mount a specific folder from nextcloud simply add the path after <username>:
sudo mount -t davfs https://files.newro.co/remote.php/dav/files/<username>/My/Super/folder/Path ~/nextcloud
Please unmount the nextcloud directory when finished, makes it harder to scan for big directories in case a VM has storage issues. Plus, you're leaving your nextcloud files exposed to others.
You can unmount the directory like this:
If that doesn't remove it use instead
fusermount -u ~/nextcloud
Mount automatically at boot
Add the credentials for davfs2 in /etc/davfs2/secrets
https://<Nextcloud-URL> <username> <password>
Make sure the location where you want to mount exists or create if not
Add the mount instructions in /etc/fstab
https://<Nextcloud-URL> /mnt/davfs2-mount davfs defaults,uid=www-data,gid=www-data,_netdev,auto 0 0
Replace uid=www-data,gid=www-data with the user that will need to access the mount
Nextcloud with CAS auth
If you want to connect to a Nextcloud server that has CAS auth enabled you'll need to tell davfs2 to send a header to NC so it doesn't redirect you to CAS
#vi /etc/davfs2/davfs2.conf add_header noredir 1
No need to restart any service for this to be taken into consideration, BUT DO NOTE that the noredir option added is most probably restricted by IP on the http proxy so you'll need to check that and add your server's IP if not already.
If you get something like this when mounting /sbin/mount.davfs: warning: the server does not support locks then edit /etc/davfs2/davfs2.conf file and set use_locks 0