#!/bin/ash
# Copyright (c) 2009 Telefonsparbuch.de / Harald Becker
# alte Konfigurationsvariable importieren (falls neue nicht gesetzt)
transferFreeMb=${transferFreeMb:-$transferFeeMb}
transferDownload(){
local file="$1" f
[ -z "$transferAction" -o "$transferAction" = "OFF" ] && return 0
if [ "$transferAction" = "FILE" ];then
[ -n "$file" ] && transferDownloadFile "$file"
elif [ "$transferAction" = "MB" ];then
# Sonderfälle: UnrRAR Verzeichnis und OTHER Dateien jedes mal verschieben
# Unrar-Ordner
if [ "$transferActionRAR" = 1 ];then
local moveDir="${unrar_extractDir:-$targetdir/unrar}"
moveDir="${moveDir%/}"
local oldIFS="$IFS";export IFS="$N"
for f in $(allFiles "$moveDir");do
local dir="$(echo -n "$f" | sed -e 's,[^/]*$,,')"
transferDownloadFile "$f" "${dir#$moveDir}"
if [ -d "$dir" -a "$dir" != "$moveDir" -a -z "$(ls $dir)" ];then
rm -r $dir
fi
done
export IFS="$oldIFS"
fi
# OTHER-Files in Download-Ordner
# ohne .failed / .part / .rar /.r01 / .part01
if [ "$transferActionOTHER" = 1 ];then
local oldIFS="$IFS";export IFS="$N"
for f in $(ls -1 "$targetdir");do
file="$targetdir/$f"
if [ -f "$file" -a "${f%.failed}" = "$f" ];then
if [ "$(echo -n "$f" | sed -e 's,\(.r[0-9ar][0-9ar]*\|.part[0-9]*\)$,,')" = "$f" ];then
transferDownloadFile "$file"
fi
fi
done
export IFS="$oldIFS"
fi
local free="$(free_diskspace "$targetdir")"
if [ -n "$free" -a "$transferFreeMb" -gt 0 -a "$free" -lt "$transferFreeMb" ];then
local oldIFS="$IFS";export IFS="$N"
for file in $(ls -1 "$targetdir");do
# keine .failed und .part Dateien
#?: "${file%.failed}" = "$file" -a
if [ -f "$file" -a "${file%.part}" = "$file" ];then
transferDownloadFile "$targetdir/$file"
fi
done
export IFS="$oldIFS"
fi
fi
}
# ${var#/} ==> $var ohne führendes "/"
# ${var%/} ==> $var ohne endendes "/"
transferDownloadFile(){
local file="$1" targetDir="${2%/}" params= url= try=1
transferDir="${transferDir%/}"
targetDir="$transferDir$targetDir"
targetDir="${targetDir%/}/"
# via ftp server
if [ -n "$transferServer" ];then
if [ -n "$transferUser" ];then
params=" -u $transferUser:$transferPasswd"
fi
transferServer="${transferServer%/}"
url="$transferServer"
if [ -n "$targetDir" ];then
url="$url/${targetDir#/}"
fi
url="${url%/}/"
# --proxytunnel -x proxy:port
while [ $try -le 3 ];do
msg "Transfer: $file --- $url"
if $pdir/curl -T "$file"$params "$url";then
msg "Transfer erfolgreich: lösche lokal $file"
rm -f $file
fi
errmsg "Transfer failed $(curl_error_code "$?")"
try=$(($try+1))
done
else
[COLOR="Red"]# /dev/null ?
if [ -c "$targetDir" ];then
msg "Character-Device: $targetDir. Delete $file"
rm -f $file
return
fi[/COLOR]
msg "Transfer: $file --- $targetDir"
[ ! -e $targetDir ] && mkdir -pm 0777 $targetDir
# Schreibrechte vorhanden + Laufwerk bereit?
local max=3
while ! touch $targetDir/fritzload_chk.tmp; do
sleep 10
max=$(($max-1)); [ $max -eq 0 ] && break
done
rm -f $targetDir/fritzload_chk.tmp
mv "$file" "${targetDir%/}/" || errmsg "Transfer failed"
fi
}