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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check whether files are transferred or not using ftp?
# 1  
Old 03-26-2013
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
# 2  
Old 03-26-2013
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.
# 3  
Old 03-26-2013
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
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 Smilie
# 5  
Old 03-26-2013
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.

...

# 6  
Old 03-27-2013
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check if any files are being FTP'ed currently ?

how to check if any files are being FTP'ed currently ? both FTP in and FTP out. And is there any system log for all the FTP activities ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. UNIX for Beginners Questions & Answers

Limit number of files transferred

I've a folder in remote server and it has 50 files. I like to transfer these files by first 10 and next 10 files. I'm using mget command to transfer the files. How to limit the file transfer limit to 10. instead of copying 50 files at a time. Thanks Janarthan (5 Replies)
Discussion started by: Janarthan
5 Replies

3. Shell Programming and Scripting

0kb file transferred in FTP process

We are transferring xml files to remote machine through cronjob @every 5 mins and then will move the files to the backup folder is source server. Sometimes the file is transferred as 0kb to destination server, whereas the file in the source backup folder is completely written. There is no error... (6 Replies)
Discussion started by: Bhavi
6 Replies

4. Solaris

How do files transferred via ftp or sftp gets thier permissions at destination?

We have umask defined under /etc/.login as 022. I have my user specific umask defined in /userhome/.login as 002. I understand ftp will not execute anything at destination, it simply transfers files. But it seem to be using 022 as umask for the files transferred. How does ftp knows what umask... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

Validating the size of file transferred from ftp server to the local system

Validating the size of file transferred from ftp server to the local system. File type: Text file/Flat file Source System: Windows / Unix Systems Target System is always: Unix Mode of Transfer : ASCII We have generic ftp shell script that transfers the files from different ftp servers. ... (2 Replies)
Discussion started by: jpundalik
2 Replies

6. UNIX Desktop Questions & Answers

Need to ftp some files, and check the number of rows in the transferd file

1)I need to write a script which ftps 3 files to a unix box, 2)once the files are ftped i need to check the number of rows in each file and compare it with the data (no of rows) coming in a manifest file, if the number of rows in each file matches the data coming in manifest file, then i need to... (3 Replies)
Discussion started by: imran_affu
3 Replies

7. UNIX for Dummies Questions & Answers

How files can be transferred from one system to another securely using Linux?

i need to know how files can be transfered from one system to another securely in linux. (9 Replies)
Discussion started by: bibing
9 Replies

8. Shell Programming and Scripting

How do I write a ksh script that will check if all ftp files are received?

I am trying to code a ksh script that will check to see if all 26 incoming ftp files have been received before proceeding to the next function, which is to rename each file. Here is the pseudo-code of what I am trying to do: <<STEP_1>> IF all ALS files have been transmitted then... (2 Replies)
Discussion started by: doug145
2 Replies

9. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

10. Shell Programming and Scripting

How to know number files transferred

Hi, I am transferring files from our local server to remote server using FTP command in a shell script. I am using a the following code, FTPFILE="ercchk*.txt" mput $FTPFILE can any one help me out in calucalating the number of files transfered. help in this regard is highly... (9 Replies)
Discussion started by: azazalis
9 Replies
Login or Register to Ask a Question