Differences
This shows you the differences between the selected revisions of the page.
guide_automation_conditional 2018-01-29 | guide_automation_conditional 2022-10-21 (current) | ||
Line 25: | Line 25: | ||
See also: | See also: | ||
- | * [[script_checking_file_existence|Checking file existence]]; | + | * [[script_checking_file_existence|*]]; |
- | * [[script_downloading_when_done_file_exists|Downloading files from FTP/SFTP server only after "done" file is created]]; | + | * [[script_downloading_when_done_file_exists|*]]; |
- | * [[library_powershell|Using WinSCP .NET assembly from PowerShell]]; | + | * [[library_powershell|*]]; |
* Example for ''[[library_session_fileexists#powershell|Session.FileExists]]'' (complete code for above example); | * Example for ''[[library_session_fileexists#powershell|Session.FileExists]]'' (complete code for above example); | ||
- | * Example [[library_example_check_existence_timestamp|Checking file existence and timestamp]] (showing how to test a local and a remote file existence and how to compare local and remote file timetamps). | + | * Example [[library_example_check_existence_timestamp|*]] (showing how to test a local and a remote file existence and how to compare local and remote file timetamps). |
===== [[scripting]] Conditions in a Batch File ===== | ===== [[scripting]] Conditions in a Batch File ===== | ||
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/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc754335(v=ws.11)|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> | ||
See also: | See also: | ||
- | * [[script_checking_file_existence|Checking file existence]]; | + | * [[script_checking_file_existence|*]]; |
- | * [[script_downloading_when_done_file_exists|Downloading files from FTP/SFTP server only after "done" file is created]]; | + | * [[script_downloading_when_done_file_exists|*]]; |
* [[guide_automation#results|Checking script results]]; | * [[guide_automation#results|Checking script results]]; | ||
- | * [[guide_automation_advanced|Advanced FTP/SFTP scripting]]; | + | * [[guide_automation_advanced|*]]; |
- | * [[guide_interpreting_xml_log|Interpreting XML log for advanced scripting]]. | + | * [[guide_interpreting_xml_log|*]]. |