Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

GVFS for Accessing Files Over Any Protocol

19 May 2012

The GNOME Virtual Filesystem lets you access files with Nautilus over many protocols as if on a filesystem. How pleased I was when I found it comes with a CLI.

GVFS would typically be used with file managers such as Nautilus, Thunar or PCManFM, to access files over FTP, PTP, WebDAV and a wealth of other protocols. However, there are also ways to get the most out of it and use it to access files in a more POSIX way with a handful of command-line interfaces.

This guide explains how to do so with a few tangible examples, with the assumption that you're not using any of the desktops environments and graphical whatsits which would normally sort it all up for you. This is useful to know when you use some of the more bare-bones window managers. You may soon want to add these commands to something like your ~/.xinitrc file.

1 Start D-BUS

It all relies on D-BUS, which you need to start and set the environment variables it will provide you with:

% export $(dbus-launch)

2 Accessing Files

Here are two notable examples you might come across when you need to access files: from your smartphone (or camera) or from a WebDAV server.

2.1 From a Smartphone, Over PTP or MTP

You'll need to work out which USB port your phone is connected to first:

% gphoto2 --auto-detect
Model                          Port                                            
My Smartphone                  usb:002,032  

Then use that information to effectively mount it:

% gvfs-mount 'gphoto2://[usb:002,032]'

Before long, you'll want to use a command line like:

% gvfs-mount "gphoto2://[$(gphoto2 --auto-detect | awk 'END { print $NF }')]"

It turns out that you can directly use gvfs-mount to work out the location too:

% gvfs-mount -li | grep activation_root

2.2 From a WebDAV Server

It's even simpler: just pass the WebDAV location as argument to gvfs-mount:

% gvfs-mount davs://dav.example.com/foo/bar/baz

3 Set Up a FUSE Mount Point

So far, when using gvfs-mount, you will have noticed that we haven't specified a mount point like we normally would with the more regular mount command. This is in fact done separately, as follows:

% mkdir ~/.gvfs
% /usr/lib/gvfs/gvfsd-fuse ~/.gvfs

It's worth noting that it doesn't matter when you do this, whether it's before running gvfs-mount or after.

4 Unmounting Filesystems

... is carried out specifying the exact same location you used for mounting it. For instance:

% gvfs-mount -u "gphoto2://[$(gphoto2 --auto-detect | awk 'END { print $NF }')]"

5 Reference