1

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is:

#! /bin/bash
today=$(date +%Y%m%d)
today_files="rec."$today"_"
programa_dir="/home/user/local-dir"

# Download files, that do not exist in the local directory
lftp <<EOF
open -u user,pass ftp1
mget "$today_files*" -O $programa_dir
bye
EOF

# Upload the files

lftp <<EOF
open -u user,pass ftp2
lcd $programa_dir
mirror -R
bye
EOF

The mirror -R command doesn't recognize that only few files do not exist on the remote directory of the second ftp.

Is there a way to fix that? I need only to check the filename's , not the creation or the modification time of the files.

For the second ftp I tried

lftp <<EOF
open -u user,pass ftp2
mput $programa_dir/* -O /
bye
EOF

The result was the same - lftp upload all the files, no only the non existing.

1
  • Does -c option (continue) work (mirror -R -c)? Maybe it understands to "resume" previous mirror operation by adding only missing files. Commented Jun 6, 2015 at 16:23

2 Answers 2

3

I don't have access to LFTP at the moment, but I suspect you're looking for the --only-missing param, which is only usable with mirror.

Try this:

lftp <<<EOF
open -u user,pass ftp2
mirror --reverse --only-newer $programa_dir/* /
bye
EOF
1
  • You mention the --only-missing parameter, however you provide --only-newer instead. Is that intentional? Commented Nov 6, 2023 at 12:39
0

If you add set xfer:clobber off; to the lftp command script, it will avoid overwriting existing files.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.