How to check whether files are transferred or not using ftp?

Hi,

i want to execute a shell script which transfers files from one server to another using ftp in unix. How can i check whether the ftp is successful or not.(i.e files are transferred to destination server). because if i am checking the return code of ftp, it always shows 0 (denoting ftp is success). but when i check the remote server , the files are not transferred. can any1 help me out.. my sample code for ftp is

ECHO="/bin/echo -e"

        ftp -n $REMOTE_MC <<_FTP1
                quote USER $REMOTE_UID
                quote PASS $REMOTE_PWD
                lcd $LOCAL_FOLDER
                cd $REMOTE_FOLDER
                prompt noprompt
                binary
                mput $LOCAL_FNAME
                quit
_FTP1
  
        RC=$?
        $ECHO "RC = $RC"
        if [ $RC -eq 0 ]; then
                $ECHO "FTP successfull....."
         else
                $ECHO "FTP failed"
         fi
fi

Thanks

The binary ftp always returns 0 as itself has no functional errors. For errors regarding the file transfer, there are other codes, which can't be accessed via $? . They can only be parsed as text output from ftp.
Can you use something else like scp ? That might make it much easier as you can use $? again and would be encrypted ie. safer. It would need an exchange of a key though because it works password-less when being used non-interactive.
If there is no way of key exchange for authentication, you could still feed it with expect for example.

Thanks for the reply zaxxon.

my requirement is to use ftp only bcoz currently in all systems we are using ftp only. if possible can u tell me some solution using FTP only.

I guess you can get the localfile as a tempfile in the same FTP logic

ECHO="/bin/echo -e"

        ftp -n $REMOTE_MC <<_FTP1
                quote USER $REMOTE_UID
                quote PASS $REMOTE_PWD
                lcd $LOCAL_FOLDER
                cd $REMOTE_FOLDER
                prompt noprompt
                binary
                mput $LOCAL_FNAME
                get $LOCAL_FNAME $TEMP_FNAME
                quit
_FTP1
  
        diff $LOCAL_FNAME $TEMP_FNAME
        if [ $RC -eq 0 ]; then
                $ECHO "FTP successfull....."
         else
                $ECHO "FTP failed"
         fi
fi

This will be helpful when you file sizes are little less :wink:

As said, parse the logfile of this script then for ftp status codes. They are defined here:

RFC 959, FTP

Example, continuing after page 39:

Postel & Reynolds                                              [Page 39]


                                                                        
RFC 959                                                     October 1985
File Transfer Protocol


         110 Restart marker reply.
             In this case, the text is exact and not left to the
             particular implementation; it must read:
                  MARK yyyy = mmmm
             Where yyyy is User-process data stream marker, and mmmm
             server's equivalent marker (note the spaces between markers
             and "=").
         211 System status, or system help reply.
         212 Directory status.
         213 File status.
         214 Help message.
             On how to use the server or the meaning of a particular
             non-standard command.  This reply is useful only to the
             human user.
         215 NAME system type.
             Where NAME is an official system name from the list in the
             Assigned Numbers document.
          
         120 Service ready in nnn minutes.
         220 Service ready for new user.
         221 Service closing control connection.
             Logged out if appropriate.
         421 Service not available, closing control connection.
             This may be a reply to any command if the service knows it
             must shut down.
         125 Data connection already open; transfer starting.
         225 Data connection open; no transfer in progress.
         425 Can't open data connection.
         226 Closing data connection.
             Requested file action successful (for example, file
             transfer or file abort).
         426 Connection closed; transfer aborted.
         227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
          
         230 User logged in, proceed.
         530 Not logged in.
         331 User name okay, need password.
         332 Need account for login.
         532 Need account for storing files.

...

hey Thanks zaxxon. i will go through wat ever you have provided me and tell you if i face some problem..thanks again..

---------- Post updated at 09:21 AM ---------- Previous update was at 09:15 AM ----------

hey thanks for the reply PiKK45. i will try your code what you gave..