Script for FTP (transfer only new files)

Hi everybody,

I just want to transfer files with FTP (mget and mput). The problem is that I dont want to overwrite any existing files and don't want to transfer them again (e.g. using the rename-function). So I only want to transfer new files with mget and mput.

My first idea was to create two listings (remote and local) and compare them, maybe with diff.

Here is my actual code:

#! /bin/sh
USER='username'
PASSWD='password'

ls /testdir > /local/local-list.txt

ftp -i -n ftp-server <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
nlist /testdir /local/remote-list.txt
quit
END_SCRIPT

diff ??? ??? > /local/new_files.txt

ftp -i -n ftp-server <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
mget ???
quit
END_SCRIPT

I need two more steps:

  1. Create a usable list with all new files listed on the ftp server
  2. Turn this list over to mget and transfer all listed

I hope anybody can help me. I'm very frustrated now. :frowning:

Best regards from germany.

Why not use rdist? [man rdist(1)]
rdist - remote file distribution program can do exactly what you want...

@vbe: Thank you for your reply. I don't know rdist - I will check this. But the server I'm connecting to (over internet) is not ours, and there is only ftp permitted. So I think I could not use rdist. Correct me if I'm wrong.

I'll checked rdist, but this was not the right tool for me.

First I tried it with the enhanced ftp-client tnftp, formerly known as lukemftp (link). But I also had some troubles with the overwrite-protection.

I found another solution: wput (link). There you can set an option, so that no files will re-loaded again. But this works only with version 0.6.2 for me.

Here is my actually code:

#! /bin/sh
HOST='servername'
USER='username'
PASSWD='password'
LOCAL_FILES='/local/dir'

wget ftp://$HOST/DIR01/* -nc --ftp-user=$USER --ftp-password=$PASSWD
wput --disable-tls --basename=$LOCAL_FILES/ $LOCAL_FILES/* ftp://$USER:$PASSWD@$HOST/DIR02/

It works great.