curl error trapping in ksh

I hope that I can trap curl errors, and have my shell script error out and quit if curl has any sort of problem.

For example, I have the following command in my shell script:

 curl --trace -n -v --ftp-ssl ftp://xxx.xxx.xxx.xxx:2122 --user user:password -o /tmp/file.txt 

Works great, except for sometimes when we have a network problem or something, and I get:

curl: (56) FTP response reading failed

So I get a good error message, but I want my whole script to send an error signal if this occurs.

In other words, I'd like the script to send a signal similar to what would occur with an 'exit 1' to the OS. I can do this with an error trapping function, but does curl have a flag or something for signaling so I don't have to write a function?

OR perhaps am I not understanding what I need to detect an error and signal?

Thank you for your time and understanding.

Neither curl nor your script is "sending" any "signals" for this. The program tells the script whether it succeeds or fails, you just have to check for it. A simple if-statement will tell if curl succeeded or not:

if ! curl --trace -n -v --ftp-ssl ftp://xxx.xxx.xxx.xxx:2122 --user user:password -o /tmp/file.txt
then
        echo error
        exit 1
fi

or even a simple

curl --trace -n -v --ftp-ssl ftp://xxx.xxx.xxx.xxx:2122 --user user:password -o /tmp/file.txt || exit 1
1 Like

Thank you! Looks like the second code line example is along the lines of what I am looking for.