Created
July 14, 2019 17:52
-
-
Save eresonance/8fee743db3a92e31a354d4bc3351a181 to your computer and use it in GitHub Desktop.
Script to pull videos from a thinkware wifi camera via ftp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
#set -x | |
usage () { | |
cat <<EOF | |
Usage: $0 [-v|--verbose] [-h|--help] [-f|--from "dirs on camera"] [-t|--to "backup location"] camera_ip | |
EOF | |
} | |
unset verbose | |
unset camera | |
unset backup_dir | |
#check these dirs for any new files | |
dirs="evt_rec manual_rec parking_rec" | |
while [ $# -gt 1 ]; do | |
case $1 in | |
-v|--verbose) | |
verbose=1 | |
;; | |
-h|--help) | |
usage | |
;; | |
-f|--from) | |
dirs=$2 | |
shift | |
;; | |
-t|--to) | |
backup_dir=$2 | |
shift | |
;; | |
-*) | |
echo "Unkown opt '$1'" | |
usage | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
if [ $# -ne 1 ]; then | |
echo "Missing camera_ip arg" | |
usage | |
exit 1 | |
fi | |
#ip address or host name of the camera | |
camera="$1" | |
if [ -z "$backup_dir" ]; then | |
backup_dir="~/${camera}/" | |
echo "Destination dir not specified, backing up to ${backup_dir}" | |
fi | |
cd ${backup_dir} | |
#ftp port to start on the camera | |
ftp_port=2121 | |
log () { | |
if [ -n "$verbose" ]; then | |
echo $@ | |
fi | |
} | |
#use fping to see if the camera exists | |
if ! fping -c1 -q "$camera" 2> /dev/null; then | |
log "$camera not found, exiting" | |
# for running in cron, just return 0 if the camera isn't on the network | |
exit 0 | |
fi | |
#ok, it's connected, pull some footage then | |
#there are a bunch of ways to do this, easiest is probably starting an ftp server | |
if ! nc -z "$camera" $ftp_port; then | |
log "Starting ftpd server on $camera..." | |
#note the -w flag to ftpd allows you to delete files on the remote end | |
set +e | |
{ | |
sleep 1; | |
echo "root"; | |
echo "start-stop-daemon -S --quiet --pidfile /var/run/ftpd.pid --exec /usr/bin/tcpsvd --make-pidfile --background -- -vE 0.0.0.0 ${ftp_port} /usr/sbin/ftpd -w /tmp/SD0"; | |
sleep 1; | |
} | telnet "$camera" > /dev/null 2>&1 | |
set -e | |
fi | |
#now make sure the ftp server is up | |
if ! nc -z "$camera" $ftp_port; then | |
echo "Could not launch ftpd on $camera, exiting" | |
exit 1 | |
fi | |
# common ncftp options | |
# user: root, no pass, port from above | |
# -DD delete files after transfer | |
# -R recursive | |
# -T do not tar a dir | |
#ncftpget does some weird stuff, turn some of it off because our busybox ftpd is super basic | |
# -o useCLNT=0,useMLST=0 | |
ncftp_opts="-u root -p '' -P $ftp_port -o useCLNT=0,useMLST=0" | |
unset found_files | |
for dir in $dirs; do | |
unset files | |
files=`ncftpls $ncftp_opts ftp://${camera}/${dir}` | |
if [ -n "$files" ]; then | |
log "Found files in $dir:" | |
for file in $files; do | |
log $files | |
done | |
found_files=1 | |
else | |
continue | |
fi | |
mkdir -p "${backup_dir}/${dir}" | |
for file in $files; do | |
ncftpget $ncftp_opts -V -DD ${camera} "${backup_dir}/${dir}" "${dir}/${file}" | |
done | |
done | |
if [ -z "${found_files}" ]; then | |
log "No files found" | |
fi |
Author
eresonance
commented
Dec 14, 2020
via email
Hmm, to be honest I don't remember how long it was taking, but I don't
think it was very quick.
My plan was to have a micro board (maybe a pi zero or something) control
the 12V sense line to the camera. Then when I got home it would leave the
camera (and wifi) on and initiate the transfer automatically between the
camera and my home server overnight. But I didn't get that far.
…On Sun, Dec 13, 2020 at 3:59 PM Tim Irvin ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks for posting this script, this was super helpful. In your
experience, how long does it normally take to download the videos? My plan
is to download them to a PI and then upload those to AWS, but in my first
test using my laptop 15 minutes in only about 1/2 of the first video had
downloaded from the Thinkware to the laptop -- at that rate the download
will never catchup. Did you have a similar experience?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/8fee743db3a92e31a354d4bc3351a181#gistcomment-3560159>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAIL5GGDFEVYYJAMJXNHSDSUUTMTANCNFSM4UZZBLAQ>
.
It looks like thinkware completely removed ftp from the new firmware (U1000). Any suggestions..?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment