Topic "Failed to connect to XX.XX.XX.244: Network error: Connection"

Author Message
fima62
[View user's profile]

Joined: 2008-10-06
Posts: 6
Hello,

I'm using a batch file to store files via SFTP to a remote Host. All is working fine and now I will do some test to verifying errore code in case of network connection problem. To do it I just modifed (on my stored session TEST) the IP address of the remote server (xx.xx.xx.244 instead of the right one xx.xx.xx.241).

This is my batch file
winscp.exe TEST /console /script=TEST.txt /log=TEST.log
if errorlevel 0 goto ARCH
if errorlevel 1 goto ERRO

:ARCH
echo "errorlevel 0" >> "c:\Program Files\WinSCP\IFO_ERR.log"
goto FINE

:ERRO
echo "erro" >> "c:\Program Files\WinSCP\IFO_ERR.log"

:FINE
echo "exit" >> "c:\Program Files\WinSCP\IFO_ERR.log"
exit

And this is my script file
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
LCD C:\Bidone
PUT 12345file.csv
# Disconnect
# close
# Exit WinSCP
exit

My question is: Why if in the Test.log file a have the following entry
. 2013-08-12 15:05:20.811 Failed to connect to XX.XX.XX.244: Network error: Connection timed out
the errorlevel that I receive is always 0 ?

Thanks to all
Marco
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
if errorlevel 0 means "if errorlevel >= 0", what is always true, even if error level is 1.
You need to query errorlevel 1 before errorlevel 0. Or use if %ERRORLEVEL% EQU 0 syntax (but that requires command extensions to be enabled).
aip

Guest


fima62 wrote:
Hello,

I'm using a batch file to store files via SFTP to a remote Host. All is working fine and now I will do some test to verifying errore code in case of network connection problem. To do it I just modifed (on my stored session TEST) the IP address of the remote server (xx.xx.xx.244 instead of the right one xx.xx.xx.241).

This is my batch file
winscp.exe TEST /console /script=TEST.txt /log=TEST.log
if errorlevel 0 goto ARCH
if errorlevel 1 goto ERRO

:ARCH
echo "errorlevel 0" >> "c:\Program Files\WinSCP\IFO_ERR.log"
goto FINE

:ERRO
echo "erro" >> "c:\Program Files\WinSCP\IFO_ERR.log"

:FINE
echo "exit" >> "c:\Program Files\WinSCP\IFO_ERR.log"
exit

And this is my script file
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
LCD C:\Bidone
PUT 12345file.csv
# Disconnect
# close
# Exit WinSCP
exit

My question is: Why if in the Test.log file a have the following entry
. 2013-08-12 15:05:20.811 Failed to connect to XX.XX.XX.244: Network error: Connection timed out
the errorlevel that I receive is always 0 ?

Thanks to all
Marco


I have the same issue. The errorlevel came back with 0. Do you have a solution for this?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
aip wrote:
I have the same issue. The errorlevel came back with 0. Do you have a solution for this?

If you have the same issue, solution is above.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License