tags:

views:

349

answers:

3

Most FTP clients return an exit code "0" even if an error occured during the file transfer.

I am facing a problem, where in I am checking for the error codes. But my script gets the error code number in the bytes sent and the validation fails.

I tried it like this:

if [[ egrep '^202 |^421 |^426 |^450 |^500 |^501 |^503 |^530 |^550 |^553 |^666 |^777 |^999 ' test.log ]] echo " Error in FTP !!! " else echo " FTP Successful !!!" fi

Can any one help me out how to segregate the error code from other numbers that come along with the message "byte sent" e.g "220 Bytes sent in 0.001 seconds (220 Kbytes/sec)"?

Any help is appreciated.

A: 

I guess that you have to be a bit more specific in your pattern, i.e., take the start of the message after the error code into the pattern.

Svante
A: 

When an error code is returned, does the message only contain the error code and no text after it? If so, using the end of line anchor $ would work:

if [[ egrep '^202$ |^421$ |^426$ |^450$ |^500$ |^501$ |^503$ |^530$ |^550$ |^553$ |^666$ |^777$ |^999$ ' test.log ]] echo " Error in FTP !!! " else echo " FTP Successful !!!" fi
jimyi
A: 

Use wget or curl. Both of them support ftp, as well as http and https, and will return the desired exit status. And they are both open source as well.

mark4o