3

I am on Debian Jessie without desktop environment. I try to mount an FTP by command line using gvfs-mount.

I gathered information on the web and I understood that gvfs comunicates with dbus.

So my first step was to install dbus and gvfs required packages :

apt-get install dbus-x11 gvfs-bin gvfs-fuse

Then I reboot, because dbus installed its own service.

After that, I am logging in as www-data

sudo -Hu www-data -s /bin/bash

(-s /bin/bash is because this user has no bash)

From here, I have to launch a dbus-daemon for my user and export the resulting DBUS_SESSION_BUS_ADDRESS in order for gvfs to communicate with that daemon. So I do:

dbus-launch --sh-syntax > "$HOME/.dbus_settings"

.dbus_settings contains something like:

cat .dbus_settings 
DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-XwbyV2BmA5,guid=6c111d728c263543b61e6293570e1f22';
export DBUS_SESSION_BUS_ADDRESS;
DBUS_SESSION_BUS_PID=952;

My environment variable DBUS_SESSION_BUS_ADDRESS is not set at this time, so I run:

export DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-XwbyV2BmA5,guid=6c111d728c263543b61e6293570e1f22'

In order to handle future gvfs mounts, I created a .gvfs folder in my user $HOME (for www-data it is /var/www)

Now, I think (but I am not sure) I have all set to use gvfs. so I launch gvfsd-fuse like this:

/usr/lib/gvfs/gvfsd-fuse $HOME/.gvfs -o big_writes

That seems to work. The folder $HOME/.gvfs appears to be mounted (but there is nothing in it yet).

The last command is the effective FTP mount:

gvfs-mount ftp://myftpuser@myftpserver < file_containing_ftp_password

But, I always get this error:

Error mounting location: Location is not mountable

These steps work on my Linux Mint 17.3 amd64 desktop. But I cannot make it work on a Debian Jessie server (without desktop and x11).

Any help is appreciated.

3

I found the problem. A package was missing gvfs-backends and some commands was useless.

To resume, the steps are :

  1. Install necessary packages:

    apt-get install dbus-x11 gvfs-bin gvfs-fuse gvfs-backends

  2. Create .gvfs folder if it does not exist

    mkdir $HOME/.gvfs

  3. Start a dbus session and store DBUS_SESSION_BUS_ADDRESS to be able to re-use it

    dbus-launch --sh-syntax > "$HOME/.dbus_settings"

  4. export DBUS_SESSION_BUS_ADDRESS using source for example

    source "$HOME/.dbus_settings"

  5. Simply mount it with gvfs-mount

    gvfs-mount ftp://myftpuser@myftpserver

Shell will prompt for your password. You can also create a file containing your password and give it to gvfs-mount so that the command will be:

gvfs-mount ftp://myftpuser@myftpserver < file_containing_my_ftp_password
  1. Access your mounted FTP at this place:

    cd $HOME/.gvfs/ftp:host\=myftpserver\,user\=myftpuser/

Done !

  • 1
    Worked for me, but the mount was located at /run/user/1000/gvfs/ – That Brazilian Guy Oct 23 '17 at 3:38
0

It would be better to use dbus-run-session some-script.sh, then you can call gio mount or other gio tool inside some-script.sh.

dbus-run-session will kill dbus-daemon after script execution, or you need to manual kill dbus-daemon if you use dbus-launch .

It would be little troublesome to use dbus-run-session because you need to write another script and call it with command dbus-run-session.

You can do like:

#!/bin/sh

sed '1,/^exit$/d' $0 | dbus-run-session sh
exit

ftp_url=ftp://root@0.0.0.0/
ftp_password=password
echo $ftp_password | gio mount $ftp_url

ftp_gio_name=$(
    gio info $ftp_url | awk '$1 == "id::filesystem:" { print $2 }'
)
ftp_gio_path=$HOME/.gvfs/"$ftp_gio_name"
archive_path=$HOME/data

cp --archive --verbose --update \
   "$ftp_gio_path"/ \
   $archive_path

gio mount -u $ftp_url

or use tail:

#!/bin/sh
tail +4 $0 | dbus-run-session sh
exit

# script here

or use heredoc:

dbus-run-session sh <<DBUS_SESSION

# script here
# but you need to escape $ and \

foo=bar
echo \$foo
touch white\\ space

DBUS_SESSION

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.