Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to automount an FTP folder using curlftpfs putting in fstab a row like:

curlftpfs#user:pwd@myhost:port/folder/ /mnt/mymountfolder fuse allow_other,uid=1000,gid=1000,umask=0022,_netdev 0 0

Normally it wouldn't work, as during the boot the network (wifi usually) is not available for my laptop. I read that _netdev option in fstab should ensure the mounting only when the network is available, but I receive the message:

Error connecting to ftp: Couldn't resolve host myhost

Alternatively I could mount the resource with an autorun script after the login has been made, but I'd like much more the fstab solution.

The final goal is to syncronize a local folder with the ftp folder with a crontab rsync, so if you have other suggestions, I will be grateful!

share|improve this question
    
Looks like during boot the system was not able to resolve to myhost. You can add a IP <=> name mapping in /etc/hosts, see if it helps. Otherwise change myhost to FQDN or IP address. –  Terry Wang Jul 17 '13 at 0:29
    
myhost is a dynamic host provided by a service such as no-ip.org or ddns.com. It's pretty unuseful to substitute it with an IP... –  jasmines Jul 17 '13 at 5:05
    
Ok,is your system able to resolve to myhost? For example, do I ping and see if you can reach it. If not, you may have to do a IP - Hostname mapping in /etc/hosts to make it work. –  Terry Wang Jul 19 '13 at 1:39
    
Please explain me why don't you use autofs? –  Danatela Jul 19 '13 at 3:48
    
Sure, I can resolve myhost! For the mapping, as already said in the previous comment, is unuseful as it's dynamic host! Autofs is quite difficult to configure, and I'm not sure it would solve the issue, as I'm investigating and I found my wireless is available only after the login. Both fstab and autofs solutions are near to be abandoned...:( –  jasmines Jul 19 '13 at 5:03

3 Answers 3

up vote 4 down vote accepted
+50

As your goal is "to syncronize a local folder with the ftp folder with a crontab rsync", I suggest you to write a small script that mounts the FTP, rsync, unmount FTP. Then run this script from crontab.

It should go something like this:

#!/bin/bash
curlftpfs user:pwd@myhost:port/folder/ /mnt/mymountfolder
#might need sleep 1 here
rsync -a /mnt/mymountfolder /local/folder
fusermount -uz /mnt/mymountfolder

Make sure you chmod +x on the script.

crontab -e

#m h d M wd
0 * * * * /usr/local/bin/backup-script

Also, if you really want the FTP folder mounted all the time, you could make a script that mounts/unmounts your drive. If you also add it to fstab, you could manually mount the drive.

fstab:

curlftpfs#user:pwd@myhost:port/folder/ /mnt/mymountfolder fuse noauto,user,uid=1000,gid=1000,umask=0022 0 0

network-mount.sh:

#!/bin/bash
folder=/media/ftp
# check if host is alive
ping=`/usr/bin/fping -q host.dyn.org`
if [ $? == 0 ]; then
  # check if folder is mounted
  mountpoint $folder > /dev/null
  if [ $? != 0 ]
    # mount, timeout in case something goes wrong
    then timeout 10s mount $folder
  fi
  else
  mountpoint $folder > /dev/null
  if [ $? = 0 ]
    #unmount lazy (network down)
    then umount -l $folder
  fi
fi

Add this to crontab (crontab -e):

* * * * * /usr/local/bin/network-mount.sh

Also watch out for your rsync not completing before the next is run. This could be done automatically(check if rsync running), or based upon how much data that need to be in sync(amount of time rsync takes, worst case scenario).

Assuming you don't run rsync for anything else, checking if it's running could be done like this:

pgrep rsync
if [ $? == 0 ]; then
  # rsync running
  exit
else
  # rsync not running
  #do stuff
fi
share|improve this answer
    
Yes, it works. The folder is correctly mounted, but rsync isn't copying anything. –  jasmines Jul 23 '13 at 11:47
    
Try adding verbose to rsync, to check whats going on. "rsync -av /media/ftp /local/folder" –  arve0 Jul 23 '13 at 13:23
    
it's a simple "operation not permitted". Note that a cp works! –  jasmines Jul 23 '13 at 19:52
    
Do you have write permission on the destination folder? ls -ld /local/folder. Are you able to browse and open files on mounted folder? What brand is your NAS? Most NAS today support more modern protocol than FTP. –  arve0 Jul 24 '13 at 8:52
1  
-a is equivalent to -rlptgoD, so it could be a number of things. For example rsync tries to preserve owner, which may fail if your not privileged to do so. Try running it as root: sudo rsync ... Without any more then, "operation not permitted", I'm not sure what it could be. Also note that rsync still copies the files in many cases where you get an error message. –  arve0 Jul 24 '13 at 21:13

I'm using SFTP / sshfs for that purpose

echo password | sshfs username@serverIP:/ /mnt/mountpointfolder -p portnumber -o reconnect -o password_stdin

Not sure if there is a fstab way. If you execute a cron job doing this every x minutes, would be ok. If the folder is already mounted, you will just get "already connected" error. If you are disconnected, you will get another error and no connection will be made. But when you are connected again, you will connect in a minute... In case of cron job you can remove -o reconnect part.

Make the script file secure as it contain the password.

share|improve this answer
    
If only my NAS could handle ssh...! –  jasmines Jul 20 '13 at 12:41
    
it does not? OMG! Dummy NASes. Who could use FTP unsecured? –  Dee Jul 20 '13 at 21:48

You may try curlftpfs option

connect_timeout=N (seconds).

In your example (let us say 30 secs are enough),

curlftpfs#user:pwd@myhost:port/folder/ /mnt/mymountfolder, uid=1000, gid=1000, umask=0022, connect_timeout=30 0 0 fuse -o allow_other

Alternatively, you can remove from fstab and connect in Nautilus, then save it as bookmark and connect each time you startup.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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