The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-08-2006 10:08 PM
Checking Exit Status PrimeRibAndADew Shell Programming and Scripting 4 10-19-2005 12:01 PM
Sending mail, status checking videsh77 UNIX for Dummies Questions & Answers 1 01-07-2005 05:17 AM
Checking the exit status of ftp psingh UNIX for Advanced & Expert Users 1 06-04-2002 07:51 PM
Couldn't open status file /var/samba/STATUS.LCK macdonto UNIX for Dummies Questions & Answers 2 08-08-2001 05:42 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-29-2008
Registered User
 

Join Date: Dec 2007
Posts: 9
checking the status of file ftp

Hi,
I m new to unix and I need a help in FTp-ing a file.

My script is given below

ftp -n <<END_SCRIPT
open $FTP_HOST
user $FTP_USER $FTP_PASSWD
lcd $TEMPFOLDER
cd $FTP_LOCATION
put $1
bye
END_SCRIPT
exit_status=$?
if [ "$exit_status" -eq "0" ] ; then
log "successfully FTPed the file"
else
log "Failed to FTP the report file"
fi


But the exit _status check doesnt seem to be working. I mean if the FTP_HOST name is given invalid, the exit_status still shows zero.

Can anyone pls tell me how else can I check for the successfult FTP of the file..
Reply With Quote
Forum Sponsor
  #2  
Old 05-29-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
If your ftp client doesn't set its exit status properly, try switch to a different one. ncftp and lftp are fairly popular, and at least the latter has some scripting support of its own.
Reply With Quote
  #3  
Old 05-29-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
This might work, try out this way,

ftp -n $FTP_HOST <<END_SCRIPT
user $FTP_USER $FTP_PASSWD
lcd $TEMPFOLDER
cd $FTP_LOCATION
put $1
bye
END_SCRIPT
exit_status=$?
if [ "$exit_status" -eq "0" ] ; then
log "successfully FTPed the file"
else
log "Failed to FTP the report file"
fi
Reply With Quote
  #4  
Old 05-29-2008
Registered User
 

Join Date: Dec 2007
Posts: 9
Thanks. But that option is not working for me. It just displays the error message in console as "unknown host or invalid literal address".
But the exit_status still shows as zero
Reply With Quote
  #5  
Old 05-29-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
No exit status error codes are defined for ftp by any standard that I am aware of. Therefore you cannot safely use $? to check exit status for errors unless your specific version of ftp supports such exit status error codes.

You need to use expect or a similar TCL to script the ftp session if you want to be able to detect session errors.
Reply With Quote
  #6  
Old 05-29-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
First off ftp is a protocol that is defined by RFC 959. This defines status reply codes, those numbers you see like 204. These are what you look for to determine what happened. Just checking the return code will not help anything in almost every case.

Quote:
There are five values for the first digit of the reply code:

1yz Positive Preliminary reply

The requested action is being initiated; expect another
reply before proceeding with a new command. (The
user-process sending another command before the
completion reply would be in violation of protocol; but
server-FTP processes should queue any commands that
arrive while a preceding command is in progress.) This
type of reply can be used to indicate that the command
was accepted and the user-process may now pay attention
to the data connections, for implementations where
simultaneous monitoring is difficult. The server-FTP
process may send at most, one 1yz reply per command.

2yz Positive Completion reply

The requested action has been successfully completed. A
new request may be initiated.

3yz Positive Intermediate reply

The command has been accepted, but the requested action
is being held in abeyance, pending receipt of further
information. The user should send another command
specifying this information. This reply is used in
command sequence groups.

4yz Transient Negative Completion reply

The command was not accepted and the requested action did
not take place, but the error condition is temporary and
the action may be requested again. The user should
return to the beginning of the command sequence, if any.
It is difficult to assign a meaning to "transient",
particularly when two distinct sites (Server- and
User-processes) have to agree on the interpretation.
Each reply in the 4yz category might have a slightly
different time value, but the intent is that the

RFC 959 October 1985
File Transfer Protocol

user-process is encouraged to try again. A rule of thumb
in determining if a reply fits into the 4yz or the 5yz
(Permanent Negative) category is that replies are 4yz if
the commands can be repeated without any change in
command form or in properties of the User or Server
(e.g., the command is spelled the same with the same
arguments used; the user does not change his file access
or user name; the server does not put up a new
implementation.)

5yz Permanent Negative Completion reply

The command was not accepted and the requested action did
not take place. The User-process is discouraged from
repeating the exact request (in the same sequence). Even
some "permanent" error conditions can be corrected, so
the human user may want to direct his User-process to
reinitiate the command sequence by direct action at some
point in the future (e.g., after the spelling has been
changed, or the user has altered his directory status.)

The following function groupings are encoded in the second
digit:

x0z Syntax - These replies refer to syntax errors,
syntactically correct commands that don't fit any
functional category, unimplemented or superfluous
commands.

x1z Information - These are replies to requests for
information, such as status or help.

x2z Connections - Replies referring to the control and
data connections.

x3z Authentication and accounting - Replies for the login
process and accounting procedures.

x4z Unspecified as yet.

x5z File system - These replies indicate the status of the
Server file system vis-a-vis the requested transfer or
other file system action.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0