DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 1st June 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,154
Thanked 182 Times in 149 Posts
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
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
Attached Files
File Type: sh ftp_auto.sh (844 Bytes, 61 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
 

Tags
auto-fetch, ftp, script, shell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent to freebsd fetch pbd OpenBSD General 9 7th August 2009 11:45 AM
Best way to upgrade from -release to snapshot Carpetsmoker OpenBSD General 5 26th July 2009 08:51 PM
portupgrade -af, how to submit fetch options? bsdfan FreeBSD Ports and Packages 4 28th December 2008 09:05 PM
Auto-YES? wubrgamer FreeBSD Ports and Packages 7 24th September 2008 01:58 PM
linux-flashplugin fetch error. bsdnewbie999 FreeBSD General 5 16th May 2008 05:40 AM


All times are GMT. The time now is 03:47 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick