shell script help needed to manage FTP automation

Hi,
I am very new in shell scripting. Have managed to prepare a script which will work to download data to local directory. But facing below problem. :wall:

Please help me out. Thanks in advance.

Problem:

  1. I am unable to use delete command to delete data in the ftp location (I have permission to delete).

  2. I don't want to download or delete data which are under precessing, file will have .curr extention.

complete file name sample: icdr.5_8_2A.0.1.201209131146.000014.0
complete file name sample: icdr.5_8_2A.0.1.201209131146.000014.curr

naming convention: icdr.version_number.zone_id.cdr_id.timestamp.sequence.new_sequence_indicator

my script:

#!/usr/bin/ksh
# CDR file location
SRC_1="/u01/raw/testcdr/"
#Credential

ipadd="myIPaddress"
user="userid"
pass="password"
remotedir="/cdr/ICDR/primary/"
pref="icd*"
TEMP_LIST_FILE="tempfilecheck_CDR"
FTPFLAGS="-n"


ftpresult1=`ftp $FTPFLAGS $ipadd <<EOF
    user $user $pass
    bin
    prompt
    cd $remotedir
    nlist $pref $TEMP_LIST_FILE
    bye
    EOF`


for i in `cat $TEMP_LIST_FILE`;do
        ftpresult2=`ftp $FTPFLAGS $ipadd <<EOF
        user $user $pass
        bin
        prompt
        cd $remotedir
        lcd $SRC_1
        mget $i
        bye
        EOF`
done

Does your system have ssh or scp available? ftp is extremely hard to automate.

I don't see your script deleting anything. What are you trying to delete, how do you try to delete it, and in what way does it not work?

Please explain your script further. I'm not entirely clear on what your first step does. Please show what ends up in your $TEMP_LIST_FILE.

Your second step is a pointless and dangerous use of backticks.

I also suspect you don't need to run ftp 5,000 times to download 5,000 files.

Why are you putting the second ftp in backticks if you never use the result?

I don't think you need mget to download individual files.

Your here-documents will not work, because the ending EOF must be at the beginning of the line, not indented.

Maybe something like this?

ftp $FTPFLAGS $ipadd <<EOF
    user $user $pass
    bin
    prompt
    cd $remotedir
    nlist $pref $TEMP_LIST_FILE
    bye
EOF


cat <<EOF > /tmp/$$
    user $user $pass
    bin
    prompt
    cd $remotedir
EOF

awk '!/[.]curr$/ { print "get " $0 } END { print "bye" }' $TEMP_LIST_FILE >> /tmp/$$

ftp $FTPFLAGS $ipadd < /tmp/$$

rm -f /tmp/$$ $TEMP_LIST_FILE