Differences
This shows you the differences between the selected revisions of the page.
guide_automation_advanced 2016-01-22 | guide_automation_advanced 2022-10-21 (current) | ||
Line 10: | Line 10: | ||
Use language of your preference. If you have no preference or do not know any scripting language, the easiest may be to use scripting engines available in Windows: | Use language of your preference. If you have no preference or do not know any scripting language, the easiest may be to use scripting engines available in Windows: | ||
* Windows command interpreter (''cmd.exe'') to run ''.bat'' or ''.cmd'' files (for simple tasks); | * Windows command interpreter (''cmd.exe'') to run ''.bat'' or ''.cmd'' files (for simple tasks); | ||
- | * Windows script host (''[[http://technet.microsoft.com/en-us/library/bb490887.aspx|cscript.exe]]'' or ''[[http://technet.microsoft.com/en-us/library/bb490816.aspx|wscript.exe]]'') to run Java Script or VB Script files. | + | * Windows script host (''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cscript|cscript.exe]]'' or ''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/wscript|wscript.exe]]'') to run Java Script or VB Script files. |
===== [[batch_file]] Windows command interpreter (batch files) ===== | ===== [[batch_file]] Windows command interpreter (batch files) ===== | ||
Line 26: | Line 26: | ||
It supports all the features listed in Windows command interpreter section above (with greater flexibility). Plus it includes many advanced functions, you may find useful when using together with WinSCP. See sections below. | It supports all the features listed in Windows command interpreter section above (with greater flexibility). Plus it includes many advanced functions, you may find useful when using together with WinSCP. See sections below. | ||
- | To use the examples below copy the JScript code to file (e.g. ''example.js'') and use ''[[http://technet.microsoft.com/en-us/library/bb490887.aspx|cscript.exe]]'' to execute it (use ''/nologo'' to suppress banner): | + | To use the examples below copy the JScript code to file (e.g. ''example.js'') and use ''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cscript|cscript.exe]]'' to execute it (use ''/nologo'' to suppress banner): |
<code batch> | <code batch> | ||
cscript /nologo example.js | cscript /nologo example.js | ||
Line 32: | Line 32: | ||
==== [[inout]] Access to Input/Output streams ==== | ==== [[inout]] Access to Input/Output streams ==== | ||
- | You can use ''[[msdn>aew9yb99|WScript.Shell]]'' to execute WinSCP [[executables|console interface tool]] and feed the script commands (using input stream), without creating temporary script file: | + | You can use ''[[https://learn.microsoft.com/en-us/previous-versions/aew9yb99(v=vs.85)|WScript.Shell]]'' to execute WinSCP [[executables|console interface tool]] and feed the script commands (using input stream), without creating temporary script file: |
<code javascript> | <code javascript> | ||
var shell = WScript.CreateObject("WScript.Shell"); | var shell = WScript.CreateObject("WScript.Shell"); | ||
Line 49: | Line 49: | ||
</code> | </code> | ||
- | ==== XML parsing ==== | + | ==== [[wsh_xml_parsing]] XML parsing ==== |
- | You can use ''[[msdn>ms756987|MSXML2.DOMDocument]]'' object to parse [[logging_xml|XML log]] produced by WinSCP. The following example follows up to the previous one (which starts session with XML logging and lists contents of initial directory): | + | You can use ''[[https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms756987(v=vs.85)|MSXML2.DOMDocument]]'' object to parse [[logging_xml|XML log]] produced by WinSCP. The following example follows up to the previous one (which starts session with XML logging and lists contents of initial directory): |
<code javascript> | <code javascript> | ||
// parse XML log file | // parse XML log file | ||
Line 92: | Line 92: | ||
</code> | </code> | ||
- | //See also guide to [[guide_interpreting_xml_log|interpreting XML log for advanced scripting]] (uses C# language, though could be easily rewritten to JScript or VB script).// | + | //See also the guide [[guide_interpreting_xml_log|*]] (uses C# language, though could be easily rewritten to JScript or VB script).// |
==== Hidden execution ==== | ==== Hidden execution ==== | ||
- | When executing JScript code with ''[[http://technet.microsoft.com/en-us/library/bb490887.aspx|cscript.exe]]'', console window is shown. If you want to execute the JScript without showing console window, use ''[[http://technet.microsoft.com/en-us/library/bb490816.aspx|wscript.exe]]'' instead. | + | When executing JScript code with ''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cscript|cscript.exe]]'', console window is shown. If you want to execute the JScript without showing console window, use ''[[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/wscript|wscript.exe]]'' instead. |
Some notes for using ''wscript'': | Some notes for using ''wscript'': | ||
* Every call to ''WScript.Echo'' causes message box to be shown, pausing the execution. So generaly you do not want to use ''WScript.Echo'' from ''wscript.exe'' (except maybe to report errors). | * Every call to ''WScript.Echo'' causes message box to be shown, pausing the execution. So generaly you do not want to use ''WScript.Echo'' from ''wscript.exe'' (except maybe to report errors). | ||
- | * Execution of ''winscp.com'' opens new console window (if one is not opened already, e.g. by ''cscript.exe''). Use ''winscp.exe'' instead (without ''[[commandline#scripting|/console]]'' switch). However ''winscp.exe'' does not allow input/output redirection, so you need to pass the commands in [[scripting#using_scripting|using command-line]]. | + | * Execution of ''[[executables|winscp.com]]'' opens new console window (if one is not opened already, e.g. by ''cscript.exe''). Use ''[[executables|winscp.exe]]'' instead (without ''[[commandline#scripting|/console]]'' switch). However ''winscp.exe'' does not allow input/output redirection, so you need to pass the commands in [[scripting#using_scripting|using command-line]]. |
===== .NET (C# or VB.NET) ===== | ===== .NET (C# or VB.NET) ===== | ||
- | See [[guide_dotnet|guide to using WinSCP from .NET]]. | + | See [[guide_dotnet|*]]. |
- | ===== External script interpreters (PHP, Perl, etc) ===== | + | ===== [[external]] External script interpreters (PowerShell, PHP, Perl, etc) ===== |
If you are familiar with other scripting languages, you can use those. | If you are familiar with other scripting languages, you can use those. | ||
- | Note that while you may find installing new scripting engine to Windows troublesome, you may not need to install anything actually. E.g. for using PHP interpreter, you can just grab the [[http://www.php.net/downloads.php|Windows binary PHP zip package]] and extract ''php.exe'' and ''php5ts.dll'' files out of it. These two binaries alone support most (if not all) features you need. No installing or registration is required. | + | All versions of Windows since Windows XP have PowerShell available. With PowerShell, it is more convenient to use [[library_powershell|WinSCP .NET assembly]], than the simple scripting. There are lot of [[library_examples|examples of use of the WinSCP .NET assembly in PowerShell]]. |
+ | |||
+ | If you want to use your another favorite scripting language, but you do not have it on your Windows machine, you may find installing it troublesome. But you may not need to install anything actually. E.g. for using PHP interpreter, you can just grab the [[https://www.php.net/downloads.php|Windows binary PHP zip package]] and extract ''php.exe'' and ''php7ts.dll'' files out of it. These two binaries alone support most (if not all) features you need. No installing or registration is required. | ||
Having the two binaries you can execute PHP script ''example.php'': | Having the two binaries you can execute PHP script ''example.php'': | ||
Line 137: | Line 139: | ||
* [[scripting|Scripting]] documentation; | * [[scripting|Scripting]] documentation; | ||
* Guide to [[guide_automation|automation]]; | * Guide to [[guide_automation|automation]]; | ||
- | * [[faq#scripting_automation|FAQ about scripting]]; | + | * [[faq#scripting|FAQ about scripting]]; |
* Example [[scripts|scripts]]. | * Example [[scripts|scripts]]. | ||