checking the status of file ftp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers checking the status of file ftp
# 1  
Old 05-29-2008
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..
# 2  
Old 05-29-2008
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.
# 3  
Old 05-29-2008
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
# 4  
Old 05-29-2008
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 zeroSmilie
# 5  
Old 05-29-2008
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.
# 6  
Old 05-29-2008
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.
 
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 see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. UNIX for Advanced & Expert Users

FTP commands to check the file status

Hi Experts, Can some one let me know the FTP commands to check the file status i.e i want to check whether my files are locked or in open status. I am connecting FTP from local machine. Regards, Spidy (1 Reply)
Discussion started by: spidy
1 Replies

3. Shell Programming and Scripting

Checking FTP server file exist or not

I am trying to delete old file in ftp server, after transferring new file successfully . but here i am checking both the file available or not using ls command. if both the file available means i need to get file_new and file_old file size as greater than zero. but i am getting only for... (3 Replies)
Discussion started by: elango963
3 Replies

4. Shell Programming and Scripting

Checking directory status

Can I use -ctime/-mtime to verify if a particular directory has been updated or not? I don't care about number of days. I just want to perform some operations only if the folder is modified (or it's metadata is modified), i.e. some files are added to the directory. This thread has a more... (1 Reply)
Discussion started by: Pramit
1 Replies

5. Shell Programming and Scripting

checking the status of sendmail

Hi All, I like to check the status of sendmail and take the appropriate action based on success / failure etc. I have gone through one of the thread where a suggestion is made to use RC for return code Following is the code: ================================== #!/usr/bin/bash export... (0 Replies)
Discussion started by: tmanda
0 Replies

6. Shell Programming and Scripting

Checking the status of mail sent.

Hi, Is there any way to check the status of the mail sent or not.e.g mail -s "Error Message" abc@xyz.com <aaa/bbb/data.txt Can it return a status code which will confirm the delivery of mail sent?Please suggest. Thanks, Anil (1 Reply)
Discussion started by: anil029
1 Replies

7. Shell Programming and Scripting

Checking the size of a file after FTP

Hi I am doing a FTP process through which I am copying a file from my local server to Remote server. After this I want to check the size of the file Below is my program: LOCALDIR=/batch/ediprocess REMOTESERVER=test.appl.com REMOTEPATH=batch/ftpTest LOGIN=px PASSWORD=abcd ftp -n... (3 Replies)
Discussion started by: shanth_chandra
3 Replies

8. Shell Programming and Scripting

ftp a file after checking the versions not greater then 8 in archive directory

Hi , I want to write a FTP Script which checks the No of Vesions of the files in Archive Dir and if count >= 8 Delete the oldest file from the Archive Dir and if the count is <= 8 Move the file to the Archive Dir with a CurrentDate concatenation and FTP the file to the FTP directory and send... (1 Reply)
Discussion started by: kailash.jadhav
1 Replies

9. Shell Programming and Scripting

Checking Exit Status

I hope one of you smart people out there can help me with what seems like a real simple questing but I can't quite figure out. In a script I am doing a cmp on two files. I am trying to check the exit status with an if statement but can't seem to figure out the syntax. If the exit status is 1 I... (4 Replies)
Discussion started by: PrimeRibAndADew
4 Replies

10. UNIX for Dummies Questions & Answers

file status during FTP

Help!!!! Can Anyone out there help me? I need to write a script to automate a task to translate files. The files will be transfered through ftp to the workstation. Is there a way to check the file status whether the file has finished being transfered or still transfering. Or is there a way to... (3 Replies)
Discussion started by: sean76
3 Replies
Login or Register to Ask a Question