Shell Script for FTPing

Shell Script for FTPing

Post by Tony Barbe » Sat, 14 Jan 1995 22:52:41



Hi,

does anyone have any basic shell scripts which open an ftp session and
send or recieve a file(s)
already written ?  I am trying to save myself the task of writing them
from scratch.

Many thanks

Tony Barber


 
 
 

Shell Script for FTPing

Post by Lonnie Rhod » Sun, 15 Jan 1995 00:56:56


1. On the local machine, create .netrc under the home directory of username:

        machine vixen.cso.uiuc.edu  login anonymous  password ftp_user_passwd

2. chmod 600 /home/username/.netrc

3. Create a script, /home/username/ftpsession, such as the following:

#! /usr/bin/sh

ftp vixen.cso.uiuc.edu <<!
cd /gnu
bin
get bison-1.22.tar.gz
get diffutils-2.6.tar.gz
get gawk-2.15.5.tar.gz
get gcc-2.5.8.tar.gz
quit
!

4. crontab -e

        00 4 * * * /home/username/ftpsession

5.  The files will be depostited in home/username directory

--

Lonnie D. Rhodes, Jr.

Phone: (407) 635-7521
FAX  : (407) 635-7500

 
 
 

Shell Script for FTPing

Post by Jeff McAdams (J M » Sun, 15 Jan 1995 01:10:59


: Hi,

: does anyone have any basic shell scripts which open an ftp session and
: send or recieve a file(s)
: already written ?  I am trying to save myself the task of writing them
: from scratch.

Well, ftp pretty much has this ability built into itself with the macro
language.  Check out the man page and look for the information on the
.netrc file.  I'm a little fuzzy on how it works as I've only used it
once, but I think it will do what you want.

Chill,
J McA

 
 
 

Shell Script for FTPing

Post by Phil Edwar » Tue, 17 Jan 1995 14:18:21


[redirects to c.u.questions]



:does anyone have any basic shell scripts which open an ftp session and
:send or recieve a file(s) already written ?

You could do something like:
==============================================================
#!/bin/csh

echo "open the.name.of.the.site \
user JoeQAverage \
password whateverthatis \
ascii \
get /whatever/the/file/is \
bye " | ftp -n -i
=============================================================

The obvious advantage is that the parameters, and even the commands,
that are inside the script can be command-line parameters (e.g., "user
$1 \" and "password $2 \"), although that carries its own risks.

--
Phil Edwards                    | The gods do not protect fools.  Fools

--------------------------------|                          -Larry Niven

 
 
 

Shell Script for FTPing

Post by Andre Be » Wed, 18 Jan 1995 02:55:50




|> : Hi,
|>
|> : does anyone have any basic shell scripts which open an ftp session and
|> : send or recieve a file(s)
|> : already written ?  I am trying to save myself the task of writing them
|> : from scratch.
|>
|> Well, ftp pretty much has this ability built into itself with the macro
|> language.  Check out the man page and look for the information on the
|> .netrc file.  I'm a little fuzzy on how it works as I've only used it
|> once, but I think it will do what you want.
|>

Besides from using .netrc which is a bit dubious, why not just do:

#!/bin/sh
ftp -i -n <<THE_END
open ftp.blafasel.edu

cd /pub/stuff
get foo
get bar
bye
THE_END

--
+-o-+--------------------------------------------------------+-o-+
| o |               \\\- Brain Inside -///                   | o |
| o |                   ^^^^^^^^^^^^^^                       | o |

+-o-+--------------------------------------------------------+-o-+

 
 
 

Shell Script for FTPing

Post by Owen Willia » Thu, 19 Jan 1995 19:31:09



> Hi,
> does anyone have any basic shell scripts which open an ftp session and
> send or recieve a file(s)
> already written ?  I am trying to save myself the task of writing them
> from scratch.

--
This is one of my `pride and joys'.  I call it `netget', I even like
the name.

--
#! /bin/ksh

if [ $1 = "-hash" ]
then
   hash='-hash'
   shift
fi

grep $1 ~/.netrc >/dev/null 2>/dev/null

if [ $? -ne 0 ]
then

fi

ftp -i $1 <<!
bin
`shift
   if [ ${1} = 'ls' ]
   then
      shift
      echo "ls $*"
   elif [ ${1} = 'cat' ]
   then
      shift
      for i in $*
      do
         echo "cd ${i%/*}"
         echo "get ${i##*/} -"
      done
   else
      if [ "${hash}" = "-hash" ]
      then
         echo hash
      fi

      for i in $*
      do
         echo "ls $i"
         echo "cd ${i%/*}"
         echo "mget ${i##*/}"
      done
   fi`
!
--

These are example calls:

netget ftp.microsoft.com ls
netget ftp.microsoft.com ls /pub
netget ftp.microsoft.com ls /pub/*

netget ftp.microsoft.com cat index.txt
netget ftp.microsoft.com cat *.txt

netget ftp.microsoft.com /pub/xv-3.10.tar.gz
netget ftp.microsoft.com /pub/xv-3.10/*.c

netget -hash ftp.microsoft.com /pub/xv-3.10.tar.gz

Enjoy,

Owen.

o------------------------------------------------------------------o
| Owen Williams        | Remember:                                 |
| Room 2.11 JW         |   Still waters run deep,                  |

| Home: (01162) 334265 |   Muddy Waters sings the Blues.           |
|------------------------------------------------------------------|
| World Wide Web Home Page : http://www.cms.dmu.ac.uk/~williams    |
o------------------------------------------------------------------o

 
 
 

Shell Script for FTPing

Post by Daniel F. Wygant (Federal Imaging Syste » Thu, 19 Jan 1995 23:17:41


how about:
#!/bin/ksh
if [ "$#" != "1" ]
then
  file_of_files=fof.txt
else
  file_of_files=$1
fi

if [ ! -f "$file_of_files ]
then
  echo "USAGE: $0 [file-of-files (default fof.txt)]"
  exit 1
fi

lsfile=/usr/mylogin/listing
load_dir=/usr/mylogin/load_dir
cd $load_dir

Quote:>$lsfile

isok=0

for fl in `cat $file_of_files`
do

  echo $fl

  while [ ! -s $fl ]
  do

    date>$lsfile

    echo "verbose
          binary

          cd /pub/wantogo2
          get $fl
          close
          bye" \
    | ftp -h -i -n whatsamatau.edu>>$lsfile

  done

  echo "ok"
  ls -ls /usr/$fl

done

echo All done!!!



|> |> : Hi,
|> |>
|> |> : does anyone have any basic shell scripts which open an ftp session and
|> |> : send or recieve a file(s)
|> |> : already written ?  I am trying to save myself the task of writing them
|> |> : from scratch.
|> |>
|> |> Well, ftp pretty much has this ability built into itself with the macro
|> |> language.  Check out the man page and look for the information on the
|> |> .netrc file.  I'm a little fuzzy on how it works as I've only used it
|> |> once, but I think it will do what you want.
|> |>
|>
|> Besides from using .netrc which is a bit dubious, why not just do:
|>
|> #!/bin/sh
|> ftp -i -n <<THE_END
|> open ftp.blafasel.edu

|> cd /pub/stuff
|> get foo
|> get bar
|> bye
|> THE_END
|>
|> --
|> +-o-+--------------------------------------------------------+-o-+
|> | o |               \\\- Brain Inside -///                   | o |
|> | o |                   ^^^^^^^^^^^^^^                       | o |

|> +-o-+--------------------------------------------------------+-o-+

--
Have Fun :)
  Dan Wygant, Sr. S/W Analyst, Federal Imaging Systems

  http://fsdsrv.b15.ingr.com/fsd/fis/dfwygant.html
  http://fsdsrv.b15.ingr.com/fsd/fis/image.html
  http://www.ingr.com/

 
 
 

Shell Script for FTPing

Post by Markus Landgr » Fri, 20 Jan 1995 18:51:18



    >> Hi, does anyone have any basic shell scripts which open an ftp
    >> session and send or recieve a file(s) already written ?  I am
    >> trying to save myself the task of writing them from scratch.

    Owen> -- This is one of my `pride and joys'.  I call it `netget',
    Owen> I even like the name.

[Shell script and description deleted]

There is a pearl script named ftpget on the net, it's very
flexibile. Furthermore you can edit you .netrc file to automatically
get files with 'macdef init', look at the manpage.

--
------------------------------------------------------------------------------
Landi#2 (http://crunch.ikp.physik.th-darmstadt.de/~landgraf)

"The only time when I'm easy is when I'm killed by death"
"If you got the power, that don't mean you got the right"
                                                          I. Kilmister
------------------------------------------------------------------------------

 
 
 

Shell Script for FTPing

Post by Bob Palowo » Sat, 21 Jan 1995 02:03:28


: Hi,

: does anyone have any basic shell scripts which open an ftp session and
: send or recieve a file(s)
: already written ?  I am trying to save myself the task of writing them
: from scratch.

: Many thanks

: Tony Barber


In the xv distribution there are two little getweather ftp scripts which
I thought where useful. You can stick them in your crontab.

#!/bin/csh -f
#
# getweather - gets the latest weather GIF image file from the anonymous ftp
# area of the server machine (SERVERHOST), in the directory (DIRNAME)
# and copies it to the file WEATHERFILE if successful
#
# this should be run hourly, on the half-hour,  in a crontab entry
#
# John Bradley, 03/26/92
#
# based on getnettables, by John Dotts Hagan

set SERVERHOST  = vmd.cso.uiuc.edu
set DIRNAME     = wx
set ACCT        = anonymous

set HOSTMANAGER = root
set WEATHERFILE = /usr/local/lib/weather.gif

set FNAME = SA`date -u +'%m%d%H'`.GIF

unset noclobber
cd /tmp
echo "open $SERVERHOST\
user $ACCT $PASS\
bin\
hash\
cd $DIRNAME \
get $FNAME \
quit" | ftp -n -i -v -d

if ( ! -e $FNAME) then
#       echo "new weather file $FNAME was not created" \
#               | /usr/ucb/mail -s "getweather error" "$HOSTMANAGER"
        exit(-1)
endif

if (-z $FNAME) then
#       echo "new weather file $FNAME is empty" \
#               | /usr/ucb/mail -s "getweather error" "$HOSTMANAGER"
        exit(-1)
endif

cp $FNAME $WEATHERFILE.1
rm $FNAME
mv $WEATHERFILE.1 $WEATHERFILE

----- cut -------------------------------------------------

#!/usr/bin/ksh
#
# getweather - gets the latest weather GIF image file from the anonymous ftp
# area of the server machine (SERVERHOST), in the directory (DIRNAME)
# and copies it to the file WEATHERFILE if successful
#
# this should be run hourly, on the half-hour,  in a crontab entry
#
# John Bradley, 03/26/92
#
# based on getnettables, by John Dotts Hagan
##
## Modified by Marc Evans to allow for the specification of the file type
## desired. The types are:
##
##    -i    CImmddhh.GIF    Infared cloud image (Cloud Infared)
##    -v    CVmmddhh.GIF    Visual cloud image (Cloud Visual)
##    -g    SAmmddhh.GIF    Ground based weather (Surface Analysis)
##    -u2   U2mmddhh.GIF    Wind characteristics at 2000 feet?
##    -u3   U3mmddhh.GIF    Wind characteristics at 3000 feet?
##    -u5   U5mmddhh.GIF    Wind characteristics at 5000 feet?
##    -u7   U7mmddhh.GIF    Wind characteristics at 7000 feet?
##    -u8   U8mmddhh.GIF    Wind characteristics at 8000 feet?

## Default paramete
SERVERHOST=vmd.cso.uiuc.edu
DIRNAME=wx
ACCT=anonymous
PASS=zk3.dec.com
HOSTMANAGER=root
FTP=gate-ftp

## Start up the ftp process
$FTP -n -i -v $SERVERHOST |&

## Loop through all of the options
for i in $* ; do

    ## Allow the command line to specify the type of image to get
    case "$i" in
        -i)    PREFIX="CI";;
        -v)    PREFIX="CV";;
        -g)    PREFIX="SA";;
        -u2)   PREFIX="U2";;
        -u3)   PREFIX="U3";;
        -u5)   PREFIX="U5";;
        -u7)   PREFIX="U7";;
        -u8)   PREFIX="U8";;
        *)     PREFIX="SA";;
    esac

    ## Determine the most recent file of the type requested
    ## (Note that we can't assume that the ls command will sort for us)
    print -p "user $ACCT $PASS"
    print -p "cd $DIRNAME"
    print -p "ls $PREFIX*"
    FNAME=`while read -p line ; do
        if [ "$line" = "250 List completed successfully." ] ; then
            break
        fi
        echo $line
    done | sort | egrep "$PREFIX[0-9]+" | tail -1 | sed 's/ GIF.*/.GIF/'`
    TARGET="/tmp/$FNAME"

    ## Go get the file if needed
    if [ ! -f $TARGET ]; then
        print -p "binary"
        print -p "get $FNAME $TARGET"
    fi

    ## Output the name of the most recent file
    echo $TARGET
done

## Complete the process
print -p "quit"
wait
exit 0

--
+--------------------------------------------------------+

| Solaris x86 Corner http://fiver.sns.com/               |
+--------------------------------------------------------+

 
 
 

Shell Script for FTPing

Post by Dan Prit » Fri, 27 Jan 1995 07:09:44





>: Hi,

>: does anyone have any basic shell scripts which open an ftp session and
>: send or recieve a file(s)
>: already written ?  I am trying to save myself the task of writing them
>: from scratch.

Many folks have posted scripts to get /usr/ucb/ftp to do this;
instead, I would suggest you look at the ncftp package, a replacement
ftp program that will, among many other enhancements, allow you
to grab a file given a URL or its own URL-like syntax.  Alternately,
there is a command-mode tool called just "www" i think that will grab
any given url and put it into a file for you.  

ncftp is at cse.unl.edu:/pub/mgleason
--

 I like beer.    On  occasion, I  will even drink a beer to celebrate
 something important, like the fall of communism or the fact that our
 refrigerator is still working.