winscp in batch file - exit code issue

Advertisement

Menowing
Joined:
Posts:
2

winscp in batch file - exit code issue

Hi
I have an issue with my batch script. The upload is working fine, the part with the exit code not.

Any help much appreciated.

******************************************************************************************

@echo off


set WINSCP_RESULT=%ERRORLEVEL%

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\mydirectory\local\WinSCP.log" /ini=nul ^
/command ^
"open sftp://username:password@sftp.remoteserver.com/ -hostkey=""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=""" ^
"lcd c:\mydirectory\local" ^
"cd upload" ^
"put *.xls" ^
"mv *.xls *.zip" ^
"exit"


if %WINSCP_RESULT% equ 0 (
C:\mydirectory\local\blat.exe -body "successfull" -from my@domain.com -to me@domain.com -subject "successfull" -server my.smtp.com:25
) else (
C:\mydirectory\local\blat.exe -body "failed" -from my@domain.com -to me@domain.com -subject "failed" -server my.smtp.com:25
)

exit /b %WINSCP_RESULT%

******************************************************************************************

Reply with quote

Advertisement

Menowing
Joined:
Posts:
2

Re: winscp in batch file - exit code issue

martin wrote:

You have to move set WINSCP_RESULT=%ERRORLEVEL% after the call to WinSCP.

Hi
I moved it. After the upload, the script is "hanging" and it is showing the console. By manually entering an exit command it is sending the e-mail, not sure why the console window stays open.

winscp-console.jpg

Reply with quote

Advertisement

You can post new topics in this forum