The native ftp programs of FreeBSD and OpenBSD have a feature called
auto-fetching. Using this to get a single file is doable. You type something like this
Code:
ftp ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/base35.tgz
and it will log you in as an anonymous user, change to the directory and get the the file for you. For multiple files it quickly becomes a lot of typing
Code:
ftp ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/MD5 \
ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/base35.tgz \
ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/bsd \
ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/etc35.tgz \
ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/i386/floppy35.fs
You can do that in a script, but it still a lot of work, to change the ftp site for example. The following script should make that easier.
In its current state. the script has been configured to download by ftp an OpenBSD snapshot. After reading the script, you will see that it is simple to adapt to your needs or wishes.
Some tips
- The shell continuation character "\" only works as advertised, if it is the last character on the line. You can use "cat --e" to check for that. The "-e" option will show the "$" as (Do you see the error here?)
Code:
xwin="xbase35.tgz \$
xfont35.tgz \ $
xserv35.tgz \$
xshare35.tgz"$
- Run the script with "sh -nv" to check for syntax errors
- Use "sh -xv" to see the expansion of the variables
"
Code:
#!/bin/sh
# --- FTP auto-fetch script
# --- get OpenBSD snapshot
server=ftp.openbsd.org
server=openbsd.bay13.net
dir=pub/OpenBSD/snapshots/i386
# --- customizeable file sets
base="MD5 \
base35.tgz \
bsd \
bsd.rd \
comp35.tgz \
etc35.tgz \
floppy35.fs \
man35.tgz \
misc35.tgz "
xwin="xbase35.tgz \
xetc35.tgz \
xfont35.tgz \
xserv35.tgz \
xshare35.tgz"
misc="INSTALL.i386 \
INSTALL.linux \
index.txt"
# --- main function
get() {
ftplist="" # Set to null in case for second invocation
for item in $@ ; do
full_name=ftp://$server/$dir/$item
ftplist="$ftplist $full_name"
done
echo "About to get the following:"
echo "$ftplist"
ftp $ftplist
}
# --- main script
get $base
#get $xwin
#get $misc
For FreeBSD replacing ftp by the
fetch program could be an alternative.
And yes, I know there are more feature rich alternatives like
curl and
wget.
The advantage of this script is that is will run on a basic FreeBSD or OpenBSD install. So you could use it to download the curl or wget package