Differences

This shows you the differences between the selected revisions of the page.

guide_custom_commands_automation 2019-08-25 guide_custom_commands_automation 2022-10-21 (current)
Line 9: Line 9:
You will typically be using these [[custom_command#patterns|custom command patterns]]: You will typically be using these [[custom_command#patterns|custom command patterns]]:
-  * ''!E'' (session URL) to pass the current session settings to the script. If you want to pass a password too, you have to [[security_credentials|store or remember it]]. //''!E'' is supported by the latest version of WinSCP only. Older versions support only ''!S'', which does not carry all session settings.// &recent+  * ''!E'' (session URL) to pass the current session settings to the script. If you want to pass a password too, you have to [[security_credentials|store or remember it]].
  * ''!/'' and ''!'' combined to ''!/!'' to pass a full path to a selected remote file.   * ''!/'' and ''!'' combined to ''!/!'' to pass a full path to a selected remote file.
  * ''!^!'' to pass a full path to a selected local file.   * ''!^!'' to pass a full path to a selected local file.
Line 18: Line 18:
  * The application run as a custom command (be it the ''powershell.exe'' or WinSCP in a console mode) is executed in WinSCP startup directory, not in a WinSCP [[executable]] directory, nor directory shown in a local panel (in [[ui_commander|Commander interface]]). \\ So generally, you should use a full path to local files, both in the custom command itself (particularly for a path to WinSCP executable and path to the script) and the script (including a [[library_powershell#loading|path to WinSCP .NET assembly]]). \\ You can make use of ''[[local_path|%WINSCP_PATH%]]'' to refer to the WinSCP executable path.   * The application run as a custom command (be it the ''powershell.exe'' or WinSCP in a console mode) is executed in WinSCP startup directory, not in a WinSCP [[executable]] directory, nor directory shown in a local panel (in [[ui_commander|Commander interface]]). \\ So generally, you should use a full path to local files, both in the custom command itself (particularly for a path to WinSCP executable and path to the script) and the script (including a [[library_powershell#loading|path to WinSCP .NET assembly]]). \\ You can make use of ''[[local_path|%WINSCP_PATH%]]'' to refer to the WinSCP executable path.
  * If the custom command refers to files (i.e. uses [[custom_command#patterns|patterns]] like ''!'', ''!&'', ''!^!''), WinSCP window is blocked, while the command is running. Should you want to avoid that, use the ''start'' command. Though note this prevents WinSCP from uploading files back to the server, if they were modified by the command. \\ <code batch>   * If the custom command refers to files (i.e. uses [[custom_command#patterns|patterns]] like ''!'', ''!&'', ''!^!''), WinSCP window is blocked, while the command is running. Should you want to avoid that, use the ''start'' command. Though note this prevents WinSCP from uploading files back to the server, if they were modified by the command. \\ <code batch>
-cmd.exe /c start "" powershell.exe -File c:\example\example.ps1+cmd /C start "" powershell.exe -File c:\example\example.ps1
</code> </code>
  * If the command modifies a remote directory, you can run WinSCP with the ''[[commandline#operations|/refresh]]'' parameter at the end of the (PowerShell) script to have the remote panel reloaded. \\ <code powershell>   * If the command modifies a remote directory, you can run WinSCP with the ''[[commandline#operations|/refresh]]'' parameter at the end of the (PowerShell) script to have the remote panel reloaded. \\ <code powershell>
Line 33: Line 33:
When using the WinSCP .NET assembly from a [[library_powershell|PowerShell script]], the script needs to take parameters to be customized for a current session settings or selected file path, etc. When using the WinSCP .NET assembly from a [[library_powershell|PowerShell script]], the script needs to take parameters to be customized for a current session settings or selected file path, etc.
-For that use ''param'' keyword. You can also mark a parameter as mandatory using ''[[https://docs.microsoft.com/en-us/powershell/developer/cmdlet/parameter-attribute-declaration|Parameter]]'' attribute or provide a default value.+For that use ''param'' keyword. You can also mark a parameter as mandatory using ''[[https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/parameter-attribute-declaration|Parameter]]'' attribute or provide a default value.
<code powershell> <code powershell>
Line 96: Line 96:
Some real-life examples: Some real-life examples:
-  * [[library_example_verify_file_checksum|Verify checksum of a remote file against a local file over SFTP/FTP protocol]] +  * [[library_example_verify_file_checksum|*]]; 
-  * [[library_example_find_duplicate_files|Find duplicate files in SFTP/FTP server]] +  * [[library_example_find_duplicate_files|*]]; 
-  * [[library_example_recursive_search_text|Search recursively for text in remote directory / Grep files over SFTP/FTP protocol]]+  * [[library_example_recursive_search_text|*]].
===== Using Scripting ===== ===== Using Scripting =====

Last modified: by martin