Understanding exit code status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understanding exit code status
# 1  
Old 01-08-2015
Linux Understanding exit code status

I have a file with size as 120,371 bytes in local machine and trying to FTP it to a remote server using put command. say that it transferred exactly the same size of 120,371 bytes and hence it returns a 226 code.

I have a doubt on how the rule is made for 226 - if both size on local and remote are equal only it returns 226 ?. And what will be the code return if it transferred is lesser than 120,371 bytes might be due to any interruption ?
# 2  
Old 01-08-2015
226 is not a program exit code, it is a FTP status code and means closing data connection - requested file action successful.

See: List of FTP server return codes - Wikipedia, the free encyclopedia
# 3  
Old 01-08-2015
Yes, I do meant the return code after a FTP command.

so on what basis it returns 226 which in turn means "closing data connection - requested file action successful".
# 4  
Old 01-08-2015
Quote:
Originally Posted by penqueen
Yes, I do meant the return code after a FTP command.

so on what basis it returns 226 which in turn means "closing data connection - requested file action successful".
You're missing the point. When you run an ftp command, it connects to an ftp server on the target system. When you terminate the ftp session, the (local)ftp command will tell the (remote) ftp server to close the connection.

I haven't looked at the internals of the handshakes between ftp and the ftp server. The ftp server might return a status code to ftp for each requested operation or it might return a consolidated status code to ftp when the connection is closed. I would expect the former rather than the latter (and I would expect the ftp server status code to be used by the ftp utility use that status code to indicate whether or not each request (e.g., get, mget, or put) succeeded or failed. Whether or not ftp sets its exit code based on the server status report(s) isn't specified on the ftp man page on OS/X (and presumably BSD) systems. I would expect a non-zero exit status from ftp if the ftp server reports failure on any (or maybe just on the last) requested operation.

The ftp utility is not contained in the POSIX standards so I can't give you a specification of what the standards require in this area.
# 5  
Old 01-12-2015
The status messages returned during an ftp session (sometimes requires the -v flag) do not affect the final return code of the ftp client command. They are useful to check for things such as failure to change remote directory, permissions to write a file denied etc.

Unless ftp fails to connect to the host at all (before a login attempt even) you will always get a zero return code to the ftp command.

The messages you are seeing are status messages. Those from 000 to 399 are considered as normal good responses and those of 400-999 are failures, although not all the possible messages have been used. If you capture the standard output (that would normally come to the screen) in a log file, then you can scan it for these messages. I have two files that I use for this. One looking for records the start with three digits over 400, and another to exclude text such as 512 bytes sent successfully and I do all my error checking in the shell script that calls the ftp.


I hope that this clarifies things a bit.



Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 6  
Old 01-12-2015
Although ftp response codes are not part of POSIX, they are standardized by an RFC:

https://tools.ietf.org/html/rfc640

This explains the meaning of each of the digits in the 3-digit response code.

As rbatte1 noted not all of them are used on every implementation. And some do not make sense for certain implementations.

FWIW: ftp has one major security flaw: usernames and passwords are sent over the connection as plaintext. So ftp is probably okay for use inside a firewall.
# 7  
Old 01-14-2015
Quote:
Originally Posted by rbatte1
The messages you are seeing are status messages. Those from 000 to 399 are considered as normal good responses and those of 400-999 are failures, although not all the possible messages have been used.
Actually, the range is 400 to 599, not 400-999, where:
Code:
     4xx   Transient Negative Completion error-codes
     5xx   Permanent Negative Completion error-codes

The ABNF for an error-response is:
Code:
      error-response = error-code SP *TCHAR CRLF
      error-code     = ("4" / "5") 2DIGIT

This User Gave Thanks to fpmurphy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit Status of Command

Hi All, I am doing an export and import (datapump) of 4 schema. I know we can do an export of 4 schema in one command. But just want to know how to check the exit status if i do the export/import of 4 schema in different commands in background. Please suggest. Thanks, Mani (1 Reply)
Discussion started by: pvmanikandan
1 Replies

2. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

3. Shell Programming and Scripting

exit status from the script is always 0

Hi , I have a bash script , which does the network configuration. Messages from this script are dumped on console as well as stored in a log file . This script is invoked from a C code using system call . The script returns different exit code , to indicate different error cases. The... (1 Reply)
Discussion started by: abhirai
1 Replies

4. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

5. UNIX for Dummies Questions & Answers

$? = Exit status variable

hi, exit status variable $?, returns some digits. 0 ---> succes. 1..126 Failure (the program itself will decide what the numbers mean) 127 Command not found 128..254 The program did not exit normally. (E.g., it crashed, or received a signal) 255 Invalid exit code well, if $?... (4 Replies)
Discussion started by: dummydba
4 Replies

6. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

7. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

8. 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

9. Shell Programming and Scripting

exit status for isql

I'm trying to write a script that will update a table in sysbase. If it's failed then I want to rerun it one more time before exiting the script (fail due to bad value such as trying to put a string into datetime field or bad connection to the database) Well my code below will always return... (2 Replies)
Discussion started by: sirrtuan
2 Replies

10. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question