up vote 35 down vote favorite
24
share [g+] share [fb]

Debian 4 Linux

I have the following cmd line which works fine.

rsync -avr -e ssh /home/dir user@example.com:/home/

But I need to set it up now to rsync to a remote server that only has an FTP server on it. How do I go about that?

I looked at the rsync help but quickly got lost (I don't do this stuff very often).

link|improve this question

57% accept rate
4  
This is akin to asking how to use HTTP over IRC, or how to use FTP over SMTP... – Juliano Nov 11 '09 at 12:26
Maybe you could explain some of your reasoning for wanting to do this, then we can help you come up with a viable solution. – James Jul 5 '11 at 21:06
essentially i was trying to automate a backup from a shared hosting server, and didn't understand how rsync worked. i have moved to a vps now, and don't have the limitation of ftp anymore – bumperbox Jul 5 '11 at 21:58
feedback

14 Answers

up vote 17 down vote accepted

You don't. rsync can't do that for you, it is a protocol of its own and doesn't work over FTP.

You might, however, want to try csync. IIRC it provides rsync-like behaviour over HTTP. I can't comment on whether it works over FTP, you'll have to try it.

link|improve this answer
feedback

Rsync definitely isn't going to work for you for the reasons others have mentioned.

However, lftp and ncftp both have "mirror" modes that will probably meet your needs.

I use this to push stuff from my local directory to a ftp or sftp web host:

lftp -c "set ftp:list-options -a;
open ftp://user:password@your.ftp.com; 
lcd ./web;
cd /web/public_html;
mirror --reverse --delete --use-cache --verbose --allow-chown  
--allow-suid --no-umask --parallel=2 --exclude-glob .svn"
link|improve this answer
feedback

As written by esel

lftp is very good tool.

I suggest you to parametrize the script, and make use of the

exclude-glob

options, that excludes filenames using the glob feature (*,? ..) of your shell:

#!/bin/bash    
HOST="your.ftp.host.dom"
USER="username"
PASS="password"
LCD="/path/of/your/local/dir"
RCD="/path/of/your/remote/dir"
lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST; 
lcd $LCD;
cd $RCD;
mirror --reverse \
       --delete \
       --verbose \
       --exclude-glob a-dir-to-exclude/ \
       --exclude-glob a-file-to-exclude \
       --exclude-glob a-file-group-to-exclude* \
       --exclude-glob other-files-to-esclude"

My 2c ..

link|improve this answer
Helped me a great bunch. But I had to remove the "set ftp:list-options -a;" which where messing stuff up. – mat Nov 16 '10 at 20:33
Brilliant response GabrieleV - That script is brilliantly constructed! Thanks – robburgoyne Jan 18 '11 at 1:52
feedback

rsync does not work over ftp. On the remote side it needs either the rsync daemon or a shell that it can call rsync from. Ftp generally allows you to call a few commands and rsync is not one of them. There are other tools meant for automating ftp tasks like "lftp".

link|improve this answer
feedback

This seems like a good and free fit: http://sourceforge.net/projects/ftpsync/

link|improve this answer
feedback

There is weex...

Weex is an utility designed to automate the task of remotely maintaining a web page or other FTP archive. It will synchronize a set of local files to a remote server by performing uploads and remote deletes as required.

link|improve this answer
feedback

Depending of what you're actually trying to do, another completely different approach could be use curlftps to mount a ftp folder, and then maybe rsync the two "local" folders.

The installation is different depending on your distro so I can't generalize on that, but you need to installfuse and curlftpfs (prolly Debian already has fuse install by default), then:

  1. sudo apt-get install curlftpfs

  2. Make sure the fuse module is loaded (modprobe fuse)

  3. sudo curlftpfs ftp.yourserver.com /path/to/ftp/folder/ -o user=username:password,allow_other

Note that there's no space after the last comma (it's not a typo!). If you're satisfied with that or don't want to make that every time, you can add it to your fstab (usually in /etc/fstab):

curlftpfs#user:password@ftp.yourserver.com /path/to/ftp/folder/ fuse auto,user,uid=1000,allow_other 0 0

In that case, you have to make sure the fuse module is loaded before.

Be advised though, of two things:

  • That the developer dropped the project one or two years ago, so I don't know how usable/stable for the time being.
  • If the password contains a weird character curlftpfs could fail (maybe you can do something with the .netrc).
link|improve this answer
FTP Fuse and rsync is closest to the question but clearly insane on anything but a small set of small files. – Steve-o Sep 23 '11 at 21:03
Why would it be insane? By default rsync stat()s, it doesn't compare the contents. That can be done by ls -l with an ftp client. – ptman Dec 30 '11 at 11:21
feedback

Jonas S's solution can be useful depending on the circumstance, for example if you have a high download speed and slow upload, checking the files on the server might be relatively faster than uploading files unnecessarily.

You probably want to use CurlFTPFS, though: http://packages.ubuntu.com/search?suite=default&section=all&arch=any&searchon=names&keywords=curlftpfs

Although, generally, it is better to use a regular FTP client altogether instead of rsync.

link|improve this answer
feedback

I don't believe you will be able to do this, the server you are trying to Rsync to will only have an FTP server running, it will not understand the commands that Rsync is sending it.

If the reason you want to do this is that you only have access to port 21, but you have control of the server, you can change the port Rsync listens on, on the server, but this is obviously only useful if you don't want to use FTP on that port.

link|improve this answer
feedback

For what it appears you are trying to do, you could also use wget.

wget -m ftp://username:password@domain.com

link|improve this answer
That will only make a mirror of the site. You can't use this to upload your modifications. – David V. Feb 2 '11 at 10:06
feedback

Using “sitecopy” or “mirror” can save you lots of bandwidth.

They both handle efficient incremental update.

link|improve this answer
feedback

If you want to automate the task then use lftp as you can create a script as some people have posted above, you can script it all really easily to your liking, if your looking for a one time solution (i.e. you need download an entire website via ftp / move it to another server) use ncftp, its simple, install it if its not already installed:

apt-get install ncftp

or

yum install ncftp

(sorry non debian/red hat based distros..)

once installed, open ncftp in the terminal then type:

open -u ftpusername ftp.thedomain.com

It'll ask you for the password, enter it, and then:

get -R /home/remotewebsite/public_html/ /home/localwebsite/public_html/

It'll do the rest pf the work for you.. good luck

link|improve this answer
feedback

EDITED: thx to comment below by outis, I stand corrected on my previous statement. There is no solution to FTP+rsync that I'm aware of then.

link|improve this answer
1  
That page describes rsync as an alternative to ftp (the client), not how to use rsync over FTP (the protocol). – outis Dec 24 '11 at 8:57
feedback

Install sftp and then you can use rsync.

I use the following one.

rsync --delete --times --recursive --perms --owner --group --verbose --progress --stats -e ssh root@192.168.0.100:/folder1/ /folder2/
link|improve this answer
5  
That is not FTP it probably uses the sftp subsystem internal to SSH (at least that's what it does in the default config) – Server Horror Jun 12 '09 at 12:27
csync(sftp) and rsync may be the same way of working – Rajat Jun 12 '09 at 12:34
feedback

Your Answer

 
or
required, but never shown

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