View Single Post
  #1   (View Single Post)  
Old 1st June 2008
J65nko J65nko is offline
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,798
Default Customizeable FTP auto-fetch script (OpenBSD snapshot download as example)

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
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
ftp \ \ \ \
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?)
    xwin="xbase35.tgz \$
          xfont35.tgz \ $
          xserv35.tgz \$
  • Run the script with "sh -nv" to check for syntax errors
  • Use "sh -xv" to see the expansion of the variables
# --- FTP auto-fetch script
# --- get OpenBSD snapshot


# --- 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 \

misc="INSTALL.i386 \
      INSTALL.linux \

# --- main function

get() {
    ftplist=""  # Set to null in case for second invocation
    for item in $@ ; do
        ftplist="$ftplist $full_name"

    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
Attached Files
File Type: sh (844 Bytes, 137 views)
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote