If statement not working properly when STAT command executes
Hi
I am using below code to check the whether file transferred properly and file exist by using STAT command. Infact the if the STAT command fails it should go to a case statement ERROR and execute the content of that case statement. But it is not reading the error case statement properly.
(
WinSCP /command "option batch continue" "option confirm off" "open HPAY_UAT" "lcd C:\Users\a160559\Desktop\DSC_TRANS\FILES\" "cd /data/dsc_files/" "put COMP_UPDATE.log /data/dsc_files/COMP_UPDATE.log" "stat /data/dsc_files/COMP_UPDATE.log" "exit"
if %ERRORLEVEL% neq 0 goto error
echo Error or file /data/dsc_files/COMP_UPDATE.log exists
exit 0
:error
echo Error or file /data/dsc_files/COMP_UPDATE.log not exists
exit 1
) > C:\Users\a160559\Desktop\Stat_out_exec_1.log
> Infact the above code is not going to case statement error when the file doesnt exist or the file transfer fails. Is there some other way to catch the Error Code: 2 to some variable.
> I would like to know whats exact the exit 0 and exit 1 does in this code. I tried the below code too.
(
WinSCP /command "option batch continue" "option confirm off" "open HPAY_UAT" "lcd C:\Users\a160559\Desktop\DSC_TRANS\FILES\" "cd /data/dsc_files/" "put COMP_UPDATE.log /data/dsc_files/COMP_UPDATE.log" "stat /data/dsc_files/COMP_UPDATE.log" "exit"
if %ERRORLEVEL% neq 0 (
echo Error or file /data/dsc_files/COMP_UPDATE.log not exists
goto end
)
file /data/dsc_files/COMP_UPDATE.log exists
goto end
:end
echo finished
) > C:\Users\a160559\Desktop\Stat_out_exec_3.log
output was :
Can't get attributes of file '/data/dsc_files/COMP_UPDATE.log'.
No such file or directory.
Error code: 2
Error message from server: No such file
Request code: 7
Here it is not catching the exception at all.
It would be great if someone look into the code.
I am using below code to check the whether file transferred properly and file exist by using STAT command. Infact the if the STAT command fails it should go to a case statement ERROR and execute the content of that case statement. But it is not reading the error case statement properly.
(
WinSCP /command "option batch continue" "option confirm off" "open HPAY_UAT" "lcd C:\Users\a160559\Desktop\DSC_TRANS\FILES\" "cd /data/dsc_files/" "put COMP_UPDATE.log /data/dsc_files/COMP_UPDATE.log" "stat /data/dsc_files/COMP_UPDATE.log" "exit"
if %ERRORLEVEL% neq 0 goto error
echo Error or file /data/dsc_files/COMP_UPDATE.log exists
exit 0
:error
echo Error or file /data/dsc_files/COMP_UPDATE.log not exists
exit 1
) > C:\Users\a160559\Desktop\Stat_out_exec_1.log
> Infact the above code is not going to case statement error when the file doesnt exist or the file transfer fails. Is there some other way to catch the Error Code: 2 to some variable.
> I would like to know whats exact the exit 0 and exit 1 does in this code. I tried the below code too.
(
WinSCP /command "option batch continue" "option confirm off" "open HPAY_UAT" "lcd C:\Users\a160559\Desktop\DSC_TRANS\FILES\" "cd /data/dsc_files/" "put COMP_UPDATE.log /data/dsc_files/COMP_UPDATE.log" "stat /data/dsc_files/COMP_UPDATE.log" "exit"
if %ERRORLEVEL% neq 0 (
echo Error or file /data/dsc_files/COMP_UPDATE.log not exists
goto end
)
file /data/dsc_files/COMP_UPDATE.log exists
goto end
:end
echo finished
) > C:\Users\a160559\Desktop\Stat_out_exec_3.log
output was :
Can't get attributes of file '/data/dsc_files/COMP_UPDATE.log'.
No such file or directory.
Error code: 2
Error message from server: No such file
Request code: 7
Here it is not catching the exception at all.
It would be great if someone look into the code.