216

Any unix:

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).

bumperbox
  • 2,363

18 Answers18

182

rsync 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"
easel
  • 2,247
134

As written by easel, lftp is a 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"
FTPURL="ftp://$USER:$PASS@$HOST"
LCD="/path/of/your/local/dir"
RCD="/path/of/your/remote/dir"
#DELETE="--delete"
lftp -c "set ftp:list-options -a;
open '$FTPURL';
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-exclude"

Warning: make sure that the target directory exists, otherwise the cd command will fail, so operation including deleting trees of files will take place at wrong directory (root)!

I have updated script so that --delete option is disabled by defaut, enable it by uncommenting the DELETE= command.

GabrieleV
  • 1,659
92

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.

serverhorror
  • 6,538
28

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).
17

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.

Johan
  • 825
13

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

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

12

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".

Ian Kelling
  • 2,719
8

This seems like a good and free fit: https://savannah.gnu.org/projects/ftpsync/

pauska
  • 19,766
6

rclone is a nice piece of software that does directory synchronization over ftp and many other protocols including cloud storage providers (Amazon S3, Dropbox, Google Drive). It can synchronize to/from any combination of local or remote storage.

To setup an ftp remote follow these instructions.

Once that is done, the sync operation is:

rclone sync /home/dir FTP_REMOTE:/home --progress 
bernie
  • 415
5

I am using GVFS/FTP. I mount my remote FTP servers with gigolo. As they are seen as local directories almost anything working on local files works. rsync is designed to compute file hashes remotely to compare files without transferring them, but doing that with virtual files transfers the files anyway. unison and freefilesync normally work well but I met a problem when they want to rename a file thy uploaded, no problem downloading. This could be a problem with gvfs 1.6.1.

Papou
  • 51
5

You can use curlftpfs to mount ftp and use rsync after http://linux.die.net/man/1/curlftpfs

shaftmx
  • 51
  • 1
  • 1
3

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

3

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.

2

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.

Sam Cogan
  • 39,089
1

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

They both handle efficient incremental update.

0

There's also wput:

wput --timestamping --reupload --dont-continue source-files ftp://target.host/dir

The username and password are read from ~/.netrc. Otherwise, if you're not particularly concerned with security, you may supply them as ftp://username:password@target.host.

Ole Wolf
  • 470
0

I made own command-line tool for that: ftpsync

Why? Because it's simple and elegant, other tools require a lot of dependencies, sometimes compiling, sometimes doesn't work (e.g. lftp on MacOs High Sierra). Ftpsync is written in pure Python, doesn't require 3rd party libs and it's small, you can just include the file in your project.

Usage: cd to your project directory and type:

ftpsync user:pass@ftp.address.url/remote/dir --delete

--delete stands for deleting remote files which don't exist locally.

If you don't want to sync but just run raw ftp command use:

ftpsync -c '...'

It's useful for some simple operations like sending file and rename it:

ftpsync -c 'PASV; TYPE I; STOR some_file.ext; RNFR some_file.ext; RNTO some_file_renamed.ext'
Cory Knutson
  • 1,886
-7

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/
Rajat
  • 3,349