Skip to content
linscpSecure file transfer for Linux and Windows
GitHub

Automation & scripting

Exit codes and error handling

Tell whether a linscp-cli job worked, and choose what a script does when a command fails.

Reviewed

A job that fails silently is worse than one that does not run. This page shows how linscp-cli reports the outcome and how to control its reaction to errors.

linscp-cli ends with one of two codes:

Code Meaning
0 Every command ran without error.
1 A command failed and stopped the script, a prompt was answered with Abort, or the connection could not be opened.

Scripts cannot choose another code: exit takes no argument. For details beyond pass or fail, read the session log (/log=) or the XML log.

Terminal window
if linscp-cli /nointeractiveinput /script=job.txt /log=job.log; then
echo "transfer done"
else
echo "transfer failed, see job.log" >&2
exit 1
fi

option batch decides what happens when a command fails or would ask a question:

Value Behaviour
abort Stop at the first error. The exit code is 1.
continue Report the error and go on with the next command.
on Answer every question automatically with a refusal (no, cancel).
off Ask, as in an interactive session.

With /script or /command, linscp-cli starts with batch abort and confirm off, so a script stops on the first problem and overwrites files without asking. Typed or piped commands start with batch off and confirm on. Print the current values with a bare option.

Switch modes for part of a script when a failure is expected and harmless:

option batch continue
rm /tmp/upload/*.part
option batch abort
put /home/alice/build/app.tar.gz /tmp/upload/

A wildcard that matches no file is a warning by default: the command does nothing and the script goes on. To treat it as an error, add:

option failonnomatch on

Then get /exports/*.csv /home/alice/in/ fails, and the exit code tells your wrapper that there was nothing to fetch.

In batch mode linscp-cli tries to reconnect a dropped session for up to 120 seconds before it gives up. Change the limit with option reconnecttime, in seconds, or turn it off with option reconnecttime off. Retrying a whole run is a job for the shell; see script recipes.

The full list of options is on the option page.