Question : FTP Script via Unix

Hi,

I have a small unix script that uses FTP to transfer files between 2 Unix boxes. This works fine but I'm just using mget and wild-card on my file names.

What I want to do now is retrict the number of records returned. i.e. I only want to return 10 files even if more than 10 exist within the wildcard search. I have nothing in the file name tha will restrict this so was hoping there was a code way.

Script is :-

HOST='xxxxx'
USER='heather'
PASSWD='*******'
FILE='*2010020214*'

ftp -inv $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /usr/indata
lcd /usr/outdata
ascii
prompt off
mget $FILE
bye
##quit
END_SCRIPT
##exit 0

This returns 20 records with '*2010020214*' somewhere in the name, but I want to stop at 10 and ignore the rest.

Thanks
H

Answer : FTP Script via Unix

Oh yeah,
you're right, rumi78, that's this confusion with "indata" and "outdata" I already mentioned!
With "put" the solution would be fine ;-)

Anyway, I once had a similar case here, where I provided a solution looking like this:

#!/bin/sh
HOST="xxxxxx"
USER="heather"
PASSWD="*******"
CMDFILE="/tmp/rc.ftp.$$"
REMOTEDIR="/usr/indata"
LOCALDIR="/usr/outdata"
PATTERN="*2010020214*"
NUMFILES=10
LISTING=$(ftp -in $HOST <<EOF
user  $USER $PASSWD
cd $REMOTEDIR
ls $PATTERN
quit
EOF )
SLISTING=$(echo $LISTING | cut -f1-$NUMFILES -d" ")
echo  "open $HOST" > $CMDFILE
echo "user $USER $PASSWD"  >> $CMDFILE
echo "verbose" >> $CMDFILE
echo "ascii"  >> $CMDFILE
echo "cd $REMOTEDIR" >> $CMDFILE
echo "lcd $LOCALDIR" >> $CMDFILE
for FILE  in $SLISTING
  do
     echo "get $FILE" >> $CMDFILE
   done
echo "quit" >> $CMDFILE
  ftp -in < $CMDFILE
rm $CMDFILE


Basically, we use FTP to create a remote listing to then process the first 10 elements in a second FTP step.

wmp
Random Solutions  
 
programming4us programming4us