Differences
This shows you the differences between the selected revisions of the page.
2020-09-24 | 2020-11-24 | ||
Restored revision 1572941913. Undoing revision 1600940144. (martin) (hidden) | no summary (223.137.213.164) (hidden) (untrusted) | ||
Line 119: | Line 119: | ||
~~AD~~ | ~~AD~~ | ||
- | ===== [[results]] Checking script results ===== | + | winscp.exe /console /command "option batch continue"·"option confirm off"·"open sftp://apadmin:abc123@@172.22.141.242:22" "option transfer binary" "put pcmp.war /home/apadmin/" |
- | To check results of the script you can: | + | |
- | * Check exit code of WinSCP (exit code is the only relevant and reliable way to check if script completed successfully). See example below and [[faq_script_result|FAQ]]. | + | |
- | · * Save and inspect log file. [[logging_xml|XML log format]] is recommended. Use command-line parameter ''[[commandline#logging|/xmllog]]''. | + | |
- | * Save and inspect output of the script. Use [[executables|output redirection]]. | + | |
- | + | ||
- | Once you find out what was the result of the script, you can perform any action you like. E.g. after evaluating exit code of WinSCP, you can send a "success" or "error" email. For that use any command-line email client you like, e.g. [[https://www.glob.com.au/sendmail/|sendmail]].((When installing sendmail, you can ignore all references to ''/usr/lib/'' (or ''c:\usr\lib'') directories in its installation instructions, as you will be running ''sendmail.exe'' directly from a Windows batch file. Just place sendmail files to any convenient location, e.g. along with WinSCP.)) | + | |
- | + | ||
- | You should also make the batch file indicate a result in its exit code, particularly if it is called from some parent system (for example [[guide_ssis|SSIS]]). | + | |
- | + | ||
- | See an example batch file: | + | |
- | + | ||
- | <code batch> | + | |
- | winscp.com /ini=nul /script=example.txt | + | |
- | if %ERRORLEVEL% neq 0 goto error | + | |
- | + | ||
- | echo Success | + | |
- | sendmail.exe -t < success_mail.txt | + | |
- | exit /b 0 | + | |
- | + | ||
- | :error | + | |
- | echo Error! | + | |
- | sendmail.exe -t < error_mail.txt | + | |
- | exit /b 1 | + | |
- | </code> | + | |
- | + | ||
- | A similar error handling is used in [[ui_generateurl|the batch file template]] that WinSCP can generate for you. | + | |
- | + | ||
- | Where for example content of ''success_mail.txt'' may be: | + | |
- | <code> | + | |
- | From: script@example.com | + | |
- | To: me@example.com | + | |
- | Subject: Success | + | |
- | + | ||
- | The files were uploaded successfully. | + | |
- | </code> | + | |
- | + | ||
- | //If you require checking results of each command individually, you should better use the [[library|WinSCP .NET assembly]]. Alternatively, see [[guide_automation_advanced|guide to advanced scripting]] for examples of checking script results (including XML log parsing) using more powerful languages and guide to [[guide_interpreting_xml_log|interpreting XML log for advanced scripting]] using C# language.// | + | |
===== Example ===== | ===== Example ===== |