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.

  • Does -c option (continue) work (mirror -R -c)? Maybe it understands to "resume" previous mirror operation by adding only missing files. – Toni Jun 6 '15 at 16:23
0

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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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