-#!/bin/bash
+#!/usr/bin/env bash
+KEY=.slurp-key
+LEGACY='-oHostKeyAlgorithms=+ssh-dss'
+sftp=( sftp -v -P 19362 -i "$KEY" -oConnectTimeout=4 $LEGACY )
+
+if [[ ! -e "$KEY" ]];then
+ ssh-keygen -f "$KEY"
+ echo "I generated you a key! Copy $KEY.pub to devices' authorized_keys"
+ exit 1
+fi
+
+seendir="slurp-seen"
while read host path;do
- outdir="slurp-$host"
- seendir="slurp-seen"
+ outdir="slurp-$host-${path//\//,}"
{
mkdir -p "$outdir" "$seendir/$outdir"
echo "cd $path"
- sftp -v -P 19362 -i .slurp-key "slurp@$host" <<< "cd $path"$'\n'"ls -1" |
+ "${sftp[@]}" "slurp@$host" <<< "cd $path"$'\n'"ls -1" |
sed 1,2d |
while read filename;do
output_filename="$outdir/${filename/jpg/jpeg}"
echo "get -p $filename $output_filename"
fi
done
- } | sftp -v -P 19362 -i .slurp-key "slurp@$host"
+ } | "${sftp[@]}" "slurp@$host"
for f in "$outdir"/*;do
touch "$seendir/$f"
done
- rename-to-date "$outdir"/*
+ ./rename-to-date "$outdir"/*
done < .slurp-hosts