Article View: es.comp.os.linux.programacion
Article #15395Re: Script de ftp en perl
From: J.A. Gutierrez
Date: Wed, 05 Jul 2000 00:00
Date: Wed, 05 Jul 2000 00:00
131 lines
3460 bytes
3460 bytes
drf <d_a_v_i_d_a_r_r_o_b_a_n_o_j_o_r_o_b_e_s@serina.es> wrote:
: Hola grupo.
: No todo va a ser preguntas, yo voy a poner algo que me ha alegrado
: la vida.
: ๏ฟฝAguien ha necesitado realizar un script que descargue, o cargue
: unos ficheros por FTP?, yo si y me volvi loco leyendo el man del
Aqui va uno con varias posibilidades de clientes:
---------------------------------------------------------------------------
#!/bin/sh
#
# SPDsoft, Thu Nov 2, 1995
# Get files from anonymous ftp server
#
# Normal usage:
# /bin/nohup xxftp URL &
# or
# echo "/usr/local/etc/xxftp -C $HOME URL" | at 01:00 tomorrow
#
#
# See also:
# ftp(1C), NcFTP (1), xtp (1), lynx(1), wget(1), nohup (1V), at(1)
#
# Note: xtp symply execs (execlp(3V)) ftp(1C); and it doesn't work
# on systems w/o /dev/pty*, like IRIX
#
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/ucb:/usr/sbin
export PATH
CMD=`basename $0`
usage()
{
echo "Usage: $CMD [-C dir] URL..."
echo "Example: $CMD ftp://ftp.cps.unizar.es/pub/README"
exit 1
}
set -- `getopt C:h $*`
if [ $? != 0 ]
then
usage
fi
for i in $*
do
case $i in
-C) cd $2; shift; shift;;
-h) usage; shift;;
--) shift; break;;
esac
done
if [ "$1" = "" ]
then
usage
fi
LOG=xxtp.$$.log
for URL in $*
do
HOST=`echo $URL | awk -F/ '{print $3}'`
DIR=`echo $URL | awk -F/ '{for(i=4; i<NF; i++) printf("/%s", $i)}'`
FILE=`echo $URL | awk -F/ '{print $NF}'`
exec >> $LOG 2>&1
date
echo File: $FILE
echo Path: $DIR
echo Host: $HOST
case ${FTP_CLIENT:=ftp} in
ncftp)
ncftp -r -d5 -D -R $URL
;;
xtp)
xtp -verbose -binary -retrieve "${FILE}" $HOST $DIR
;;
lynx)
lynx -source $URL > `basename $URL`
;;
wget)
wget -vc -Q5M -nd --no-parent $URL
;;
*)
ftp -n -i -v $HOST <<- @EOF
user ftp $LOGNAME@
bin
cd $DIR
hash
get "${FILE}"
@EOF
;;
esac
done
Mail -s "ftp done `date`" $LOGNAME < $LOG && rm $LOG
exit
---------------------------------------------------------------------------
: ftp. Por eso envio al grupo la solucion que le di. Esta hecho en
: perl, pero no creo que sea tan dificil, como para coger este codigo
: y adaptarlo a las necesidades de cada uno:
: -------miftp-----------
: #!/usr/bin/perl
: use Net::FTP;
trampa! de con perl, nada, con un modulo que hace el ftp :-)
--
PGP and other useless info at \ Oh, show us the way
http://www.cps.unizar.es/~spd/ \ to the next whisky bar
finger://daphne.cps.unizar.es/spd \ Weill/Bretch
es doloroso ser sabio y descubrir la sopa de ajo (Pla)
Technical Details
Message-ID:
<8jvdml$l8m$4@news.unizar.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8jup1q$ps7$1@talia.mad.ttd.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,96156d895a7482d2
X-Google-Attributes: gidf86c8,public
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Subject: Re: Script de ftp en perl
Date: 2000/07/05
Message-ID: <8jvdml$l8m$4@news.unizar.es>
X-Deja-AN: 642734321
Content-Transfer-Encoding: 8bit
References: <8jup1q$ps7$1@talia.mad.ttd.net>
Content-Type: text/plain; charset=ISO-8859-1
X-Complaints-To: usenet@news.unizar.es
X-Trace: news.unizar.es 962804245 21782 155.210.152.20 (5 Jul 2000 13:37:25 GMT)
Organization: Rank
Mime-Version: 1.0
User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (IRIX/6.2 (IP22))
NNTP-Posting-Date: 5 Jul 2000 13:37:25 GMT
Newsgroups: es.comp.os.linux.programacion