#!/bin/sh # # Get a listing of files (and directories) from a FTP site. # usage() { echo "usage: $(basename $0) [-u username -p password] hostname path" >&2 exit 1 } username=anonymous password=who@what.com while getopts ":u:p:" c do case "$c" in u) username=$OPTARG;; p) password=$OPTARG;; :|'?') usage;; esac done if [ $OPTIND -gt 1 ]; then if [ -n "$username" -a -z "$password" -o \ -n "$password" -a -z "$username" ]; then usage; fi shift $(($OPTIND - 1)) fi if [ $# -lt 2 -o $# -gt 2 ]; then usage; fi hostname=$1 path=$2 ftp -n $hostname << ! 2>/dev/null user $username $password cd "$path" ls -R quit ! .