source_dir="/c/tiles/"
destination="/home/heco/tiles/"
targets=(
  "202 王家山|192.168.101.7|35024"
  "203 灵山岛|192.168.101.7|35022"
  #  "204 乳山口|192.168.204.116|22"
  #  "215 沙子口2|192.168.215.116|22"
  #  "208 烟台宜尚|192.168.208.116|22"
)
test -d "$source_dir" || {
  echo "源目录不存在：$source_dir" >&2
  exit 1
}
for target in "${targets[@]}"; do
  IFS='|' read -r name host port <<<"$target"
  echo "========== 开始传输：$name，$host:$port =========="
  ssh -p "$port" \
    -o ConnectTimeout=15 \
    -o ServerAliveInterval=30 \
    -o ServerAliveCountMax=10 \
    "heco@$host" \
    "command -v rsync >/dev/null && mkdir -p '$destination'" || {
    echo "连接失败或远端没有安装 rsync：$name" >&2
    continue
  }
  rsync -rtvh \
    --partial \
    --partial-dir=.rsync-partial \
    --info=progress2 \
    -e "ssh -p $port -o ConnectTimeout=15 -o ServerAliveInterval=30 -o ServerAliveCountMax=10" \
    "$source_dir" \
    "heco@$host:$destination"
  if [ "$?" -eq 0 ]; then
    echo "========== 传输完成：$name =========="
  else
    echo "========== 传输失败：$name ==========" >&2
  fi
done
