Bash script: return code ftp
Hello,
I'm using the code written below inside a bash script to transfer some files. In order to test the return code from the ftp, i supplied an invalid password. I was surprised by the fact that the ftp was successful. Can anybody tell me why it was successful and how i need to adjust the code? ftp -inv <<EOF open IP-address user USER PASSWORD lcd /Dir cd /Dir binary put $1 quit EOF if [ $? -eq 0 ] then Echo “Successful” Else Echo “Failed” fi TIA TalkingMarble |
the best way to troubleshoot these situations is to enter the commands manually and look at "$?" at each step.
In your scenario, you are testing the result after issuing a series of ftp commands--not a BASH command. I don't know what happens is that case. |
The problem here is that the return code comes from the ftp command. The ftp command itself runs fine, so the return-code is true.
To test a proper ftp your sender shoud put a second file and the you have to test if this file is received. By sending do it the other way round send an extra file if your transport is finished and transport the same file in a new ftp session back. The you are sure the ftp result is ok. |
Given the explanation in the previous posts, you can redirect the standard error coming from the ftp command to a file, then check if the file has a size greater than zero and act accordingly, as in
Code:
ftp -inv << EOF 2> ftp.error |
All times are GMT -5. The time now is 02:58 AM. |