Checking FTP server file exist or not

I am trying to delete old file in ftp server, after transferring new file successfully .
but here i am checking both the file available or not using ls command.
if both the file available means i need to get file_new and file_old file size as greater than zero.
but i am getting only for file_new file size as greater than zero.not for file_old file.
why ls command not working here twice.

code:

ftp -vn $TARGET_SERVER > ${FTP_OUTPUT_FILE} 2> ${FTP_ERROR_FILE} << cmd
quote USER #####
quote PASS #####
cd TEST
put Newfile
ls Newfile file_new
ls oldfile file_old
bye
cmd

What is in the output and error logs?

Tried your script. It gave me ls output for files that do exist. My server returns 'Permission denied' on files that do not exist

What exactly are you getting for output that makes you think ls does not work?

All I see you sending over is Newfile, but none of the other files you are looking for. What renames/creates oldfile file_old - in other words why should they be there?

PS: you are supposed to check the return code

550 Permission denied.

500-599 is an error condition.

There are ftp tools more script friendly than ftp itself, like wget ftp://...

       o   The usage of FTP is as simple.  Wget will take care of login and
      password.
 
          wget ftp://gnjilux.srk.fer.hr/welcome.msg
 
     o   If you specify a directory, Wget will retrieve the directory list-
      ing, parse it and convert it to HTML.  Try:
 
          wget ftp://ftp.gnu.org/pub/gnu/
          links index.html