#!/bin/sh # # Find files at a FTP site # cmd=$(basename $0) hosts=$(cat ~/.ftpfindrc) if [ $# -eq 0 ]; then echo "usage: $cmd host pattern" >&2 exit 1 fi IFS=" " for host in $hosts; do if [ "${host%%#*}" = "" ]; then continue; fi alias=${host%%:*} if [ "$1" = "$alias" ]; then host=${host#*:}; hostname=${host%%:*} host=${host#*:}; username=${host%%:*} host=${host#*:}; password=${host%%:*} host=${host#*:}; path=${host%%:*} break fi done if [ -z "$hostname" ]; then echo "$cmd: No entry exists for host '$1'" >&2 exit 1 fi ftpgetlist -u $username -p $password $hostname $path | \ nawk -v hostname="$hostname" -v path="$path" -v pat="$2" ' BEGIN { lpat = tolower(pat) } /^-([r-][w-][SsxTt-])+.+[^:]$/ { # File size = $5; date = sprintf("%3s %2s %5s", $6, $7, $8) file = substr($0, index($0, date) + 13) if ((ldir ~ lpat) || (tolower(file) ~ lpat)) { if (dir != "") {print dir ":"; dir = ""}; print; nf++ } } /:$/ { # Directory sub(/:$/, ""); sub(/^\.\//, ""); dir = $0; ldir = tolower(dir) }' | lsfmt -s .