Re: if statement for "Connection refused"
There's no simple solution. But you can use XML logging. If it contains just empty <session/> tag (like below) and exit code is 1, it is likely that the connection has failed for some reason.
<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="my session" start="2011-02-02T07:17:47.632Z">
</session>