0

I am running lftp on Raspbian

I have 100GB of content on the remote site and 100GB space available on my SD card so I need to delete files not present at the remote site from the SD card before downloading new content.

How can I achieve this?

#!/bin/bash
login="username"
pass="password"
host="server.feralhosting.com"
remote_dir="/folder/you/want/to/copy"
local_dir="/cygdrive/s/lftp/somefolder/where/you.want/your/files/"

base_name="$(basename "$0")"
lock_file='/tmp/'"$base_name"'.lock'
trap 'rm -f '"$lock_file"'' SIGINT SIGTERM
if [[ -e "$lock_file" ]]
then
  echo "$base_name is running already."
  exit 1
else
  touch "$lock_file"
  lftp -u $login,$pass $host << EOF
  set ftp:ssl-allow no
  set mirror:use-pget-n 5
  mirror -c -P5 --log='/var/log/'"$base_name"'.log' "$remote_dir" "$local_dir"
  quit
EOF
  rm -f "$lock_file"
  trap - SIGINT SIGTERM
  exit 0
fi
1

I found the solution.

Add the --delete-first option, so this:

mirror -c -P5 --log='/var/log/'"$base_name"'.log' "$remote_dir" "$local_dir"

becomes this:

mirror -c -P5 --delete-first --log='/home/osmc/'"$base_name"'.log' "$remote_dir" "$local_dir"

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.