Differences
This shows you the differences between the selected revisions of the page.
| guide_automation_conditional 2020-12-24 | guide_automation_conditional 2022-10-21 (current) | ||
| Line 35: | Line 35: | ||
| If you do not want to use .NET assembly, for simple conditions or conditions involving local files, you may be able to move the condition outside of WinSCP [[scripting|script]] into a [[guide_automation_advanced#batch_file|wrapper batch file]]. | If you do not want to use .NET assembly, for simple conditions or conditions involving local files, you may be able to move the condition outside of WinSCP [[scripting|script]] into a [[guide_automation_advanced#batch_file|wrapper batch file]]. | ||
| - | For example you can use an ''[[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/if|if]]'' command to test a local file existence before uploading it: | + | For example you can use an [[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/if|''if'' command]] to test a local file existence before uploading it: |
| <code batch> | <code batch> | ||
| - | if exist c:\upload\test.txt winscp.com /script=upload.txt | + | if exist c:\upload\test.txt winscp.com /ini=nul /log=upload.log /script=upload.txt |
| + | </code> | ||
| + | |||
| + | If you need different conditions for individual script commands, you can generate the WinSCP script file on the fly step by step: | ||
| + | |||
| + | <code batch> | ||
| + | @echo off | ||
| + | set FILE1=c:\upload\test.txt | ||
| + | set FILE2=c:\other\file.txt | ||
| + | |||
| + | ( | ||
| + | echo open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx..." | ||
| + | if exist %FILE1% echo put %FILE1% | ||
| + | if exist %FILE2% echo put %FILE2% | ||
| + | echo <nohilite>exit</nohilite> | ||
| + | ) > upload.txt | ||
| + | |||
| + | winscp.com /ini=nul /log=upload.log /script=upload.txt | ||
| </code> | </code> | ||