How to check whether files are transferred or not using ftp? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Tags
shell script

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
Little Little is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 7 September 2014, 5:11 AM EDT
Posts: 179
Thanks: 32
Thanked 9 Times in 8 Posts
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


Code:
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
Sponsored Links
    #2  
Old 03-26-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 31 October 2014, 4:41 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,237
Thanks: 121
Thanked 453 Times in 412 Posts
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.
Sponsored Links
    #3  
Old 03-26-2013
Little Little is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 7 September 2014, 5:11 AM EDT
Posts: 179
Thanks: 32
Thanked 9 Times in 8 Posts
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.
    #4  
Old 03-26-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 10 July 2014, 12:57 PM EDT
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 Posts
I guess you can get the localfile as a tempfile in the same FTP logic


Code:
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
Sponsored Links
    #5  
Old 03-26-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 31 October 2014, 4:41 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,237
Thanks: 121
Thanked 453 Times in 412 Posts
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:

Code:
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.

...

Sponsored Links
    #6  
Old 03-26-2013
Little Little is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 7 September 2014, 5:11 AM EDT
Posts: 179
Thanks: 32
Thanked 9 Times in 8 Posts
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..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do files transferred via ftp or sftp gets thier permissions at destination? kchinnam Solaris 4 01-10-2013 08:42 AM
Validating the size of file transferred from ftp server to the local system jpundalik Shell Programming and Scripting 2 04-08-2011 01:21 PM
Need to ftp some files, and check the number of rows in the transferd file imran_affu UNIX Desktop for Dummies Questions & Answers 3 01-31-2011 05:09 PM
How files can be transferred from one system to another securely using Linux? bibing UNIX for Dummies Questions & Answers 9 03-03-2010 04:03 PM
How to know number files transferred azazalis Shell Programming and Scripting 9 08-13-2006 05:49 AM



All times are GMT -4. The time now is 06:40 AM.