Skip to content

Instantly share code, notes, and snippets.

@lucasrangit
Forked from irq0/download_flashair
Last active May 5, 2016 07:41
Show Gist options
  • Save lucasrangit/be09620f8505de0d0fc0 to your computer and use it in GitHub Desktop.
Save lucasrangit/be09620f8505de0d0fc0 to your computer and use it in GitHub Desktop.
#!/bin/bash
URL="http://flashair"
list () {
curl --silent "${URL}/command.cgi?op=100&DIR=${1}" \
| awk 'BEGIN { FS=","; OFS="/" } /.+,.+,[^0,]/ { print $1,$2 }'
}
files () {
for dir in $@; do
list "$dir"
done
}
directories () {
curl --silent "${URL}/command.cgi?op=100&DIR=DCIM" \
| awk 'BEGIN { FS=","; OFS="/" } /.+,0,/ { print $1,$2 }'
}
download () {
i="1"
for file in $@; do
echo -n "[$((i++))/$#] $file: "
mkdir -p "./$(dirname $file)"
curl --silent --continue-at - -o "./${file}" "${URL}/${file}"
if [[ $err -eq 0 ]]; then
echo "OK"
elif [[ $err -eq 52 ]]; then
echo "OK (already downloaded)"
else
echo "FAIL"
fi
done
}
download $(files $(directories))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment