| 1 | #!/bin/bash |
| 2 | |
| 3 | # ftpget - script replacement for old utility |
| 4 | # Copyright (c) 2000 Alexander V. Lukyanov <[email protected]> |
| 5 | # This file is covered by GNU GPL. See file COPYING for details. |
| 6 | |
| 7 | usage() |
| 8 | { |
| 9 | echo "Usage: $0 [OPTS] host filename [-o local] [filename...]" |
| 10 | echo " -p <port> set port number" |
| 11 | echo " -u <user[,pass]> login as user using pass as password" |
| 12 | echo " -l get listing of specified directory(ies)" |
| 13 | echo " -c reget specified file(s)" |
| 14 | echo " -q quiet (no output)" |
| 15 | echo " -v verbose (lots of output)" |
| 16 | echo " -o <file> output to this file (default - base name of filename)" |
| 17 | exit 1 |
| 18 | } |
| 19 | |
| 20 | port="" |
| 21 | user="" |
| 22 | list=false |
| 23 | cont="" |
| 24 | verb="" |
| 25 | final="set verbose yes; " |
| 26 | |
| 27 | while getopts +p:u:lcv opt |
| 28 | do |
| 29 | case $opt in |
| 30 | \?) usage;; |
| 31 | p) port=":$OPTARG";; |
| 32 | u) user="-u $OPTARG ";; |
| 33 | l) list=true;; |
| 34 | c) cont=" -c";; |
| 35 | v) verb="debug 5; ";; |
| 36 | q) final="";; |
| 37 | esac |
| 38 | done |
| 39 | while [ $OPTIND -gt 1 ] |
| 40 | do |
| 41 | OPTIND=$(($OPTIND-1)) |
| 42 | shift |
| 43 | done |
| 44 | host="$1" |
| 45 | shift |
| 46 | |
| 47 | if [ -z "$host" ]; then |
| 48 | usage |
| 49 | fi |
| 50 | |
| 51 | cmd="get$cont" |
| 52 | ok=false |
| 53 | $list && { cmd="ls"; ok=true; } |
| 54 | |
| 55 | for f |
| 56 | do |
| 57 | case "$f" in |
| 58 | "*[\"'\\]*") |
| 59 | # need to quote |
| 60 | f="`echo "$f" | sed 's/\([\\\"'\'']\)/\\\1/g'`" |
| 61 | ;; |
| 62 | esac |
| 63 | cmd="$cmd \"$f\"" |
| 64 | ok=true; |
| 65 | done |
| 66 | |
| 67 | $ok || { usage; } |
| 68 | |
| 69 | exec lftp -c "$final${verb}open $user$host$port; $cmd" |