#!/bin/sh
# ftpget - given an ftp: style URL, unwrap it, and try to obtain the file using ftp.
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
echo "Usage: $0 ftp://... username [password]" >&2
exit 1
fi
# Typical URL: ftp://ftp.ncftp.com/2.7.1/ncftpd-2.7.1.tar.gz
if [ "$(echo $1 | cut -c1-6)" != "ftp://" ] ; then
echo "$0: Malformed url. I need it to start with ftp://" >&2;
exit 1
fi
server="$(echo $1 | cut -d/ -f3)"
filename="/$(echo $1 | cut -d/ -f4-)"
basefile="$(basename $filename)"
username="$(echo $2)"
password=""
if [ $# -eq 3 ] ; then
password="$(echo $3)"
fi
#rm $basefile
echo ${0}: Downloading $basefile from server $server
ftp -n << EOF
open $server
user $username $password
bin
get $filename $basefile
quit
EOF
if [ $? -eq 0 ] ; then
#chmod +x $basefile
ls -l $basefile
fi
exit 0
# ftpget - given an ftp: style URL, unwrap it, and try to obtain the file using ftp.
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
echo "Usage: $0 ftp://... username [password]" >&2
exit 1
fi
# Typical URL: ftp://ftp.ncftp.com/2.7.1/ncftpd-2.7.1.tar.gz
if [ "$(echo $1 | cut -c1-6)" != "ftp://" ] ; then
echo "$0: Malformed url. I need it to start with ftp://" >&2;
exit 1
fi
server="$(echo $1 | cut -d/ -f3)"
filename="/$(echo $1 | cut -d/ -f4-)"
basefile="$(basename $filename)"
username="$(echo $2)"
password=""
if [ $# -eq 3 ] ; then
password="$(echo $3)"
fi
#rm $basefile
echo ${0}: Downloading $basefile from server $server
ftp -n << EOF
open $server
user $username $password
bin
get $filename $basefile
quit
EOF
if [ $? -eq 0 ] ; then
#chmod +x $basefile
ls -l $basefile
fi
exit 0
| Attachment | Size |
|---|---|
| ftpget.sh | 817 bytes |
Interesting information, I