return ftp status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting return ftp status
# 1  
Old 06-21-2002
Question return ftp status

Hello,

I still have problems when trying to figure out if the status of an ftp was successful. I ftp to different types (nt, vax, unix, etc...) of machines. I am trying to write a universal script that will ftp a file and then check to see if the ftp was successful. I have tried the following:

verify file sizes: VAX and UNIX boxes have different file sizes
grep ftp result for:
code 226; some boxes have different sayings

Do you have ideas?

Thanks,
Barbara
# 2  
Old 06-21-2002
In this post, I show the best technique that I have found to get the return codes. It is imperfect, and I'd love to see a better idea. Because it's so hard to know how long to sleep, I usually take my best shot, then double it. This technique wastes a lot of clock time.

Yeah, there are several codes that can result from an operation failing. You will need to check for them all. But it's not like every programmer can make up his own codes or anything. The codes are documented in RFC 959. Any ftp server that returns different codes is broken.

For transfers, I would just look for the presense of a code 226. That would indicate that the transfer worked. No code 226, it must've failed. But if you want to diagnose the error, this won't be enough. It depends on how far you want to go.

Also, I don't understand why your file sizes are off. This sounds like you did an ascii transfer when you needed a binary transfer.
# 3  
Old 06-21-2002
Hope this can help
ftp -v hostname
-v that will show all responses from the remote server, as well as report on data transfer statistics. This is turned on
by default if ftp is running interactively with its input coming from the user's terminal.
# 4  
Old 06-21-2002
Network

Thanks!

In the past, I have checked for "226". There have been some cases where the bytes transferred, bytes sent, or transfer time contains "226". The job result is successful, yet the ftp was not successful. So this doesn't always work for my scenario.

The translation of code 226 is not consistent on all boxes. For example, I have seen "226 Closing data connection" or "226 Transfer Complete" as a translation for code 226.

I do have -v in my ftp command line. Because the "226" code is not consistent, the status returned is not always reliable.

Thanks,
Barbara
# 5  
Old 06-21-2002
The 226 is consistent. The text that follows it is not. As the rfc says:
Quote:
It is intended that the three digits contain enough encoded information that the user-process (the User-PI) will not need to examine the text and may either discard it or pass it on to the user, as appropriate. In particular, the text may be server-dependent, so there are likely to be varying texts for each reply code.
If you get a 226 in response to a request for a transfer, the server is trying to tell you that it succeeded.

226 Transfer Complete
226 Closing Data Connection

mean almost the same thing. After a successful tranfer, the rfc allows a sever to keep a data connection open and re-use it for the next transfer. This is rarely done and the second message is underscoring that it wasn't done.

226 Everything's Groovy
226 That worked
226 looks good to me

would all be legal ways for a server to tell you that the transfer completed successfully. I've never seen anyone do that, but English is certainly not required by the rfc.

You really should read that RFC that I linked to in my earlier post. It will tell you what a server can and cannot do. The whole section on reply codes would especially help you out.
# 6  
Old 06-21-2002
Thanks.

I'm sorry I guess I didn't explain myself correctly. This is my existing code:

ftpresults=`ftp -inv $ip_box_name <<EOB
user $userid $password
put $ftp_file $downstream_name
bye
EOB`

ftp_ctr=`echo "$ftpresults" | grep "226 Transfer complete" | wc -l`
echo $ftp_ctr
if [ $ftp_ctr = 1 ]
then
echo "FTP of " $file_name " to " $ip_box_name " was successful"
echo " "
else
ftp_error="true"
fi

In my prior reply, I was trying to say that if I did a grep on "226" alone, a count of 1 would be returned if the bytes transferred were a size which contained "226". I am trying to find something in the return of the ftp to grep. This will allow me to tell me if it was successful. I read the codes that you had passed along in your prior response.

Thanks,
Barbara
# 7  
Old 06-21-2002
Try:
grep "^226"
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. Shell Programming and Scripting

Return Status

Hi can you explain me, what does variables $@ and $* return and how are they used, if can give me a sample example it could be helpful. Thanks in advance, Regards, Abhishek S. (1 Reply)
Discussion started by: abhisheksunkari
1 Replies

3. UNIX for Dummies Questions & Answers

opposite return status in c shell

there is something wrong with my system. when I do this: diff file1 file1 && echo 1 the output is 1. but diff file1 file2 >/dev/null && echo 1 output nothing while diff file1 file2 >/dev/null || echo 1 shows 1. the same with "grep" return status. they are both GNU utilities.... (5 Replies)
Discussion started by: phil518
5 Replies

4. Shell Programming and Scripting

return status after run the shell script

Hello, I wanted to delete all files which are placed 14 days back. Here is my below script. My script works very well and it deletes all files 14 days back. I wanted to display message incase if the delete script is not successful. The below script returns always successful. But the directory... (6 Replies)
Discussion started by: govindts
6 Replies

5. Shell Programming and Scripting

capturing C++ binary return status in perl

Hello, I have a C++ binary that runs in my perl script. But, Currently, the binary is doing a core dump and i want to capture the retrun status of the binary to report as an issue. Can you please help me on this. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

6. Shell Programming and Scripting

evaluate return status of a function

Hi all I'm trying to evalute the return status of a function without much success. I've put a very basic example below to explain. check_ok() works fine but when used within an if statement, it always returns true, whether it is true or false. I'm guessing it returns true as the function... (4 Replies)
Discussion started by: tig2810
4 Replies

7. HP-UX

Return of EXIT status ( $? )

I have the question: How return the exit code from then assign : VAR=$(command ) for ex. VAR=$(ls ....) VAREXIT=$? echo $VAREXIT VAREXIT is equal to 0 if the directory exist or not exist. WHI?? if i execute the command direct from line-command , the value of $? is different if... (1 Reply)
Discussion started by: ZINGARO
1 Replies

8. Shell Programming and Scripting

Verify scp return status

Hi all below is a snippet of my perl codesystem ("scp -pq $dest_file $path");How i can i trap the return status? ie if the scp fails how can i know ? (2 Replies)
Discussion started by: new2ss
2 Replies

9. Shell Programming and Scripting

Return status of all previous runs

hi, I set the crontab to execute script A every 5 minutes from 9:00 am to 4:00 pm everyday, now at 12:00am I want to run another script if and only if all the previous runs of script A return OK, can anyone tell me how it could be done? thank you very very much! (4 Replies)
Discussion started by: mpang_
4 Replies

10. Shell Programming and Scripting

Return status...

Hello there! Here is my problem. I hope I can get some help about it. I need to know how can I get the return code of an application in the Unix shell script. The script is like below: PREVIOUS STATEMENT & VARIABLES sqlplus scott/tiger @$sqldir/$sqlscript NEXT STATEMENT (Like... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question