need to check the file using ftp in a shell script

i need to write a shell script..
connecting to another server using ftp and check whether the file ter.txt is exists there or not.
i have written scirpt partially,as i new to Unix.

ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF
user $FTPUSER $FTPPW
binary
prompt
${CD}
ls *.txt /home/bin
close
bye
EOF

if you have Python, here's an alternative

import ftplib
server="localhost"
user="anonymous"
password="test@hotmail.com"
def myfilter(line):
     if "ter.txt" in line: print "found: ",line     
try:
    ftp = ftplib.FTP(server)
    ftp.login(user,password)    
except Exception,e:
    print e
else:    
    ftp.cwd("/home/bin")
    ftp.retrlines('LIST',myfilter)
    ftp.close()

Sorry yar,
I don't have python, I need shell script in unxi only.
Thnx

you can use following code:

ssh user@hostname "find . -exec grep -q "ter.txt" '{}' \; -print"

When i used shh command it showing the error as follows.

The authenticity of host 'lpdma523.dev.ipc.us.aexp.com (148.171.30.205)' can't b
e established.

both the servers are in the same environment,they are connecting.. i don't know why it is not connecting through ssh. can any one suggest

ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF
user $FTPUSER $FTPPW
binary
prompt
${CD}
ls -ltr <your_server>/ftp_files.lst
close
bye
end

i=`grep -i "<wanted_file_name>" <your_server>/ftp_files.lst`
if test "i = "" ;
then
echo "file not found"
fi

Hi Shailesh,
Thanks for reply,
But here server means ip address or wat else?

I am using the script like this, but showing error. what to give in place of <your_server>. can u plz me tell me clearly

FTPUSER="6262"
FTPPW="******"
TEMPFILE1="green.txt"
TEMPFILE2="green.txt"

ftp -inv 148.171.30.205 > $TEMPFILE1 2> $TEMPFILE1 << EOF
user $FTPUSER $FTPPW
binary
prompt
${CD}
ls -ltr 148.171.30.205/home/pbommire/Praveen/MAILBOX_TEST
close
bye
end
echo "Connection success...."
i=`grep -i "Test.txt" 148.171.30.205/home/pbommire/Praveen/MAILBOX_TEST
if test "i = "" ;
then
echo "file not found"
fi

it's not ip addr, can be lcd or any other path on server from where you started ftp session

If you try to connect to other system with ssh it will ask you for authentication. Solution for this issue is creating a trusted host and creating same set of user on both the server. After that you can connect to the other box with ssh username@servername and then execute the script which is required, in your case you execute

cd <location of file>
ls -l | `grep <filetosearch>` >/dev/null

if [ $? ]
then
echo "file exist "
fi

Hi,
i want to search a file existed in another or not using ftp command as follows. When i was using the script there was a problem like data connection is not opened. Please suggest any one..below is text.sh

FTPUSER="user1"
FTPPW="pwd1"
DIR="/home/pbommire/"
CD="cd ${DIR}"
TEMPFILE1="green.txt"
TEMPFILE2="green.txt"
ftp -inv 635.23.33.23> $TEMPFILE1 2> $TEMPFILE1 << EOF
user $FTPUSER $FTPPW
binary
prompt
${CD}
ls -ltr Praveen/test.txt
close
bye
end
echo "Connection success...."
i=`grep -i "test.txt" Praveen/test.txt`
if test "i = "" ;
then
echo "file not found"
fi

===============================
The output file green.txt as follows

Connected to 635.23.33.23.
220-Hello, Welcome toKERBEROS_V4 rejected as an authentication type
ady.
504 AUTH GSSAPI not supported.
504 AUTH KERBEROS_V4 not supported.
331 Password required for pbommire.
230 User pbommire logged in.
200 Type set to I.
Interactive mode on.
250 CWD command successful.
output to local-file: Praveen/test.txt? 227 Entering Passive Mode (635.23.33.23)
425 Can't open data connection.
221 Goodbye.

Hi,
The bove code is not checking the file existenance in Destination server. My criteria is like as
1) am in 161.21.12.12 server and make a connection to 727.12.12.12 server usning FTP (which is done by using the above partial code)
2) and i want to search a file test.txt in 727.12.12.12 server after logged using above code.

Can anyone give me the directions to achieve step2.

Thanks