The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Terminal And Cron Job Return Different Status Code isaac_ho Shell Programming and Scripting 1 06-02-2008 12:12 AM
Return of EXIT status ( $? ) ZINGARO HP-UX 1 03-12-2008 07:07 AM
Verify scp return status new2ss Shell Programming and Scripting 2 06-28-2006 10:04 PM
Return status of all previous runs mpang_ Shell Programming and Scripting 4 06-27-2006 02:58 AM
Return status... Shaz Shell Programming and Scripting 7 11-19-2002 06:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2002
blt123 blt123 is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 19
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 (permalink)  
Old 06-21-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 06-21-2002
trynew trynew is offline
Registered User
  
 

Join Date: Jun 2002
Posts: 50
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 (permalink)  
Old 06-21-2002
blt123 blt123 is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 19
Angry

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 (permalink)  
Old 06-21-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 06-21-2002
blt123 blt123 is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 19
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 (permalink)  
Old 06-21-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try:
grep "^226"
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0