Accessing Nextcloud files (and external storages) Without Syncing

The Nextcloud Desktop Sync Client does a fantastic job of syncing files between your desktop/laptop and Nextcloud's storage, but you don't always want everything synced down.

For example, we have some fairly sizeable volumes mounted as "External Storage" in Nextcloud. We wanted to be able to browse through those from desktops without having to sync >200GB of data down to each and every client.

This post details how to mount your Nextcloud instance as a remote drive, using WebDAV, so that files are only pulled over the network as and when they're opened.

The basic principle

Nextcloud has a WebDAV compatible endpoint - it allows clients to remotely access and manipulate files.

Most operating systems have support for WebDAV, so this can be used without a dedicated client, treating the Nextcloud server more like a remote network share. We actually use both, with the Nextcloud client syncing files that we want to maintain a local copy of (password manager databases being a good example).

These instructions assume you've not done anything clever like link Nextcloud to LDAP - if you have, then you can probably also figure out which steps need tweaking


The Webdav URL

The URL is pretty simple to construct, it's of the format

[your nextcloud domain]/remote.php/dav/files/[your user]/

So, for example, might be

nextcloud.example.com/remote.php/dav/files/alice/

In most cases, the scheme will be https:// but there are exceptions (detailed below).


Windows

In Windows explorer

  • Browse to "My Computer"
  • Click "Remote Network Share" in the menu area
  • Add new
  • Provide the URL https://nextcloud.example.com/remote.php/dav/files/alice/ (correcting for your domain+user)
  • Tick the Use other credentials box
  • Enter your Nextcloud credentials

You should now have a new drive which allows you to access your Nextcloud files as well as any external storage that your Nextcloud user is permitted to access


Linux

If you're using KDE/Dolphin and don't need things to mount at boot, you can use Dolphin's built in WebDAV support - simply enter the path webdav://nextcloud.example.com/remote.php/dav/files/alice/. In Gnome you can do the same using davs://nextcloud.example.com/remote.php/dav/files/alice/ (if you're not using HTTPS, you want dav rather than davs).

However, if you want the OS to mount it somewhere, you'll need to installer a helper and add it to fstab

sudo apt-get -y install davfs2
sudo mkdir /mnt/nextcloud

The system needs to be provided with your credentials

cat << EOF | sudo tee -a /etc/davfs2/secrets

/mnt/nextcloud alice mysecretpassword

EOF

Add your user to the group davfs2

sudo usermod -a -G davfs2 alice

You then have a choice between setting up so that you manually mount (including have the system do so at boot) or automounting with autofs.

Manual Mount

The mount can be added to /etc/fstab

https://nextcloud.example.com/remote.php/dav/files/alice/   /mnt/nextcloud  davfs _netdev,user,uid=alice,gid=alice  0  0

You should then be able to mount the directory

mount /mnt/nextcloud/

Automount

You might, instead, want it to automatically mount when you browse into that directory - this can be achieved with autofs.

Install autofs

sudo apt-get install autofs

Grab some basic info and generate the automount master config line

MYUID=`id -u`
GID=`id -g`
echo "/mnt/ /etc/auto.nextcloud uid=$MYUID,gid=$GID,--timeout=60,--ghost" | sudo tee -a /etc/auto.master

Then, the autofs config file needs to be created

echo "nextcloud -fstype=davfs,rw :https\://nextcloud.example.com/remote.php/dav/files/alice/" | sudo tee /etc/auto.nextcloud

Reload autofs

sudo systemctl reload autofs

And you should be good to go.

ls /mnt/nextcloud

Mac OS

It is possible to mount WebDAV shares via Finder, but is reportedly quite slow. You might prefer to use something like ocsmount instead.

Open Finder

  • Go to Go and choose Connect to Server (or press Command + K)
  • Enter https://nextcloud.example.com/remote.php/dav/files/alice/ as the server address
  • Click Connect
  • When prompted enter your Nextcloud credentials

Conclusion

Nextcloud's sync client is useful when you have files that you want to keep a local copy of (and don't mind the relative storage cost), however it's of fairly limited utility if you've a large volume of data that you want to easily browse, but do not want routinely synced to your machine.

The most obvious example of this would be an external storage filled with photographs - you want to be able to flick through them conveniently, but you also do not want them all stored on your machine, all the time.

WebDAV addresses this by providing a network drive - files are only pulled down when they're accessed, and disappear out of your local device's cache soon afterwards.

Although performance varies, the 3 main operating systems all provide support for WebDAV.