Checking the exit status of ftp | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Checking the exit status of ftp

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-17-2002
psingh psingh is offline
Registered User
 
Join Date: May 2002
Last Activity: 7 May 2009, 9:21 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Checking the exit status of ftp

#!/bin/sh
# upload_file.sh

FILENAME=$1

ftp -v -n -i <<-EOF1
open remote_server
user username password
cd remote_directory
lcd local_directory
type binary
mput ${FILENAME}
EOF1
rc=$?
echo "Return code is ${rc}"


I am calling this script from another script.
My problem is that the exit status of the above script is always 0, i.e. successful, even if remote_directory, local_directory or FILENAME don't exist.

I want to check the exit status of this script in the calling script and take appropriate action based on whether the ftp was successful or not. I am not sure if I am doing something wrong.
Sponsored Links
    #2  
Old 06-04-2002
random random is offline
Registered User
 
Join Date: Jun 2002
Last Activity: 30 August 2007, 5:44 PM EDT
Location: North Texas
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
This is not so much as checking the exit code but a way to validate the transfer:

FILENAME=$1

ftp -v -n -i <<EOF > /tmp/ftplog.$$
<<<ftp stuff>
EOF

Then either in the upload script or in the calling script store the size of the file just tranferred into an environment variable using ls -l and awk. Then cat /tmp/ftplog.$$. You want to grep for the line that reads "XXX bytes transferred" (or however it reads. It's been a long time since I've done this) and awk out the "XXXX" bytes into a second environment variable.

In the upload script it is simple to do a comparision and "exit 1" for an imcomplete or failed transfer. You could also cat/grep the tmplog for other error conditions such as failure to cd to the appropriate directories, etc. and exit with different return codes depending on the nature of the failure.

Either way this should be enough information point in you in the best direction you need to validate your transfers.

NOTE: this method works for binary transfers only. Ascii transfers show a lower number of bytes transfered.
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
Exit status MartyIX Shell Programming and Scripting 9 09-09-2008 05:47 AM
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-09-2006 01:08 AM
Checking Exit Status PrimeRibAndADew Shell Programming and Scripting 4 10-19-2005 03:01 PM
exit status moxxx68 Shell Programming and Scripting 1 12-04-2004 06:27 PM
ftp exit status. oracle8 UNIX for Advanced & Expert Users 1 10-21-2001 11:34 PM



All times are GMT -4. The time now is 03:53 PM.