Differences

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

extension 2017-01-18 extension 2023-03-30 (current)
Line 1: Line 1:
====== WinSCP Extensions ====== ====== WinSCP Extensions ======
-A WinSCP extension is a text file with a standardized metadata syntax that defines a [[custom_command|custom command]]. As such, it can be easily distributed and [[ui_pref_commands#extensions|installed into WinSCP]].+A WinSCP extension is a text file with a standardized metadata syntax that defines a [[custom_command|custom command]]. As such, it can be easily distributed and [[ui_pref_commands#extensions|installed into WinSCP]]. The installed extensions can then be [[custom_command#executing_and_configuring|executed]] as any other custom command.
The extension file can include solely the metadata, if the defined custom command relies on standard tools only (such as [[commandline|WinSCP command-line]], [[scripting]], built-in Windows commands, etc.). Though typically the extension file will include an actual code too, that implements the extension. In that case the custom command definition will refer to the file itself using ''[[#name|%EXTENSION_PATH%]]'' variable and the extension metadata will be escaped using [[#syntax|"comments" syntax]] of the respective language. The language can be a Windows batch-file (potentially using the WinSCP [[scripting]]), a PowerShell script (potentially using [[library|WinSCP .NET assembly]]), or other language. The extension file can include solely the metadata, if the defined custom command relies on standard tools only (such as [[commandline|WinSCP command-line]], [[scripting]], built-in Windows commands, etc.). Though typically the extension file will include an actual code too, that implements the extension. In that case the custom command definition will refer to the file itself using ''[[#name|%EXTENSION_PATH%]]'' variable and the extension metadata will be escaped using [[#syntax|"comments" syntax]] of the respective language. The language can be a Windows batch-file (potentially using the WinSCP [[scripting]]), a PowerShell script (potentially using [[library|WinSCP .NET assembly]]), or other language.
Line 13: Line 13:
All metadata are prefixed with ''@'', followed by a metadata key, space(s) or tab(s), and a value. All metadata are prefixed with ''@'', followed by a metadata key, space(s) or tab(s), and a value.
-The metadata line have to start with the ''@'', optionally escaped with some recognized "single-line comments" syntax. The recognized comment syntaxes are ''rem'' (Windows batch file), ''#'' (e.g. WinSCP script, PowerShell, %%Perl%%, Python), ''%%//%%'' (e.g. JavaScript), ''%%'%%'' (VBScript).+The metadata line have to start with the ''@'', optionally escaped with some recognized "single-line comments" syntax. The recognized comment syntaxes are ''rem'' (Windows batch file), ''#'' (e.g. WinSCP script, PowerShell, %%Perl%%, Python), ''%%//%%'' (e.g. JavaScript), ''%%'%%'' (VBScript). A metadata line can continue on following line(s) by using ''^'' at the end of the line. The following line(s) can also be escaped with a comment syntax, the same way as the first line.
The recognized metadata keys are: The recognized metadata keys are:
Line 20: Line 20:
| ''@==name=='' | Name of the custom command. \\ You can insert ampersand (''&'') before a letter to make it a keyboard accelerator. The name should end with ''%%...%%'' (ellipsis), if some prompt is displayed (confirmation or input) before the actual command is executed). For example ''%%&Grep...%%''. \\ This key is mandatory. | | ''@==name=='' | Name of the custom command. \\ You can insert ampersand (''&'') before a letter to make it a keyboard accelerator. The name should end with ''%%...%%'' (ellipsis), if some prompt is displayed (confirmation or input) before the actual command is executed). For example ''%%&Grep...%%''. \\ This key is mandatory. |
| ''@command'' | The actual [[custom_command|custom command]]. \\ The command will typically include some [[custom_command#patterns|custom command patterns]] and may use ''%EXTENSION_PATH%'' variable to refer to the extension file itself. You can also use ''[[scripting#variables|%WINSCP_PATH%]]'' to refer to the WinSCP executable path, or any other environment variable. \\ This key is mandatory. | | ''@command'' | The actual [[custom_command|custom command]]. \\ The command will typically include some [[custom_command#patterns|custom command patterns]] and may use ''%EXTENSION_PATH%'' variable to refer to the extension file itself. You can also use ''[[scripting#variables|%WINSCP_PATH%]]'' to refer to the WinSCP executable path, or any other environment variable. \\ This key is mandatory. |
-| ''@require'' | Defines extension dependencies. Prevents installing the extension on a system that does not meet extension requirements. \\ Recognized dependencies are: \\ ''WinSCP'' - Defines a minimal supported version of WinSCP, e.g. ''@require WinSCP 5.8.2'' \\ ''Windows'' - Defines a minimal supported version of Windows, e.g. ''@require Windows 6.1'' (for Windows 7)\\ ''.NET'' - Defines a minimal supported version of .NET framework, e.g. ''@require .NET 4.5'' \\ ''PowerShell'' - Defines a minimal supported version of PowerShell, e.g. ''@require PowerShell 5.0'' \\ To define multiple dependencies, use multiple ''@require'' entries on separate lines. |+| ''@require'' | Defines extension dependencies. Prevents installing the extension on a system that does not meet extension requirements. \\ Recognized dependencies are: \\ ''WinSCP'' -- Defines a minimal supported version of WinSCP, e.g. ''@require WinSCP 5.8.2'' \\ ''Windows'' -- Defines a minimal supported version of Windows, e.g. ''@require Windows 6.1'' (for Windows 7)\\ ''.NET'' -- Defines a minimal supported version of .NET framework, e.g. ''@require .NET 4.5'' \\ ''PowerShell'' -- Defines a minimal supported version of PowerShell, e.g. ''@require PowerShell 5.0'' \\ To define multiple dependencies, use multiple ''@require'' entries on separate lines. |
| ''@side'' | ''Local'' or ''Remote'' [[custom_command#types|type of custom command]]. \\ Defaults to ''Local''. | | ''@side'' | ''Local'' or ''Remote'' [[custom_command#types|type of custom command]]. \\ Defaults to ''Local''. |
-| ''@flag'' | Custom command option. \\ Recognized options are: \\ ''ApplyToDirectories'' - Makes the command be executed even for selected directories. Makes sense for commands that work with files only (patterns ''!'', ''!&'' and ''%%!^!%%''). \\ ''Recursive'' - Makes the command be executed for files in selected directories. Makes sense for commands that work with single file only (pattern ''!''). \\ ''ShowResults'' - Makes the output of the custom command be shown in [[ui_console|Console window]]. Can be used with the ''Remote'' type custom commands only. The local commands can use their own Windows console window. \\ ''CopyResults'' - Makes the output of the custom command be copied to a clipboard. Can be used with the ''Remote'' type custom commands only. The local commands can make use of an API of their language to copy a contents to the clipboard. \\ ''RemoteFiles'' - With ''Local'' type custom command, makes ''!'', ''!&'' and ''!/'' patterns refer to remote paths, instead of paths to a local copy of the remote files (prevents the download itself too).  \\ To set multiple options, use multiple ''@flag'' entries on separate lines. | +| ''@flag'' | Custom command option. \\ Recognized options are: \\ ''ApplyToDirectories'' -- Makes the command be executed even for selected directories. Makes sense for commands that work with files only (patterns ''!'', ''!&'' and ''%%!^!%%''). \\ ''Recursive'' -- Makes the command be executed for files in selected directories. Makes sense for commands that work with single file only (pattern ''!''). \\ ''ShowResults'' -- Makes the output of the custom command be shown in [[ui_console|Console window]]. Can be used with the ''Remote'' type custom commands only. The local commands can use their own Windows console window. \\ ''ShowResultsInMsgBox'' -- Makes the output of the custom command be shown in message box. \\ ''CopyResults'' -- Makes the output of the custom command be copied to a clipboard. Can be used with the ''Remote'' type custom commands only. The local commands can make use of an API of their language to copy a contents to the clipboard. \\ ''RemoteFiles'' -- With ''Local'' type custom command, makes ''!'', ''!&'' and ''!/'' patterns refer to remote paths, instead of paths to a local copy of the remote files (prevents the download itself too).  \\ To set multiple options, use multiple ''@flag'' entries on separate lines. | 
-| ''@shortcut'' | Associates [[custom_key_shortcuts|custom keyboard shortcut]] with the custom command. |+| ''@==shortcut=='' | Associates default [[custom_key_shortcuts|custom keyboard shortcut]] with the custom command. The shortcut [[ui_pref_commands#extensions|can be changed by a user]]. |
| ''@description'' | Description of the custom command. Will be used as a hint in the WinSCP GUI. | | ''@description'' | Description of the custom command. Will be used as a hint in the WinSCP GUI. |
| ''@author'' | An author of the extension. Not used. | | ''@author'' | An author of the extension. Not used. |
Line 38: Line 38:
<code powershell> <code powershell>
# @name        Verify &Checksum # @name        Verify &Checksum
-# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl "!S" -localPath "!^!" -remotePath "!/!" -pause+# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%"
 +#                  -sessionUrl "!E" -localPath "!^!" -remotePath "!/!" -pause
# @description  Compares checksums of the selected local and remote file # @description  Compares checksums of the selected local and remote file
# @flag        RemoteFiles # @flag        RemoteFiles
Line 63: Line 64:
| ''type'' | Type of the option or options dialog control. \\ Supported types are: ''textbox'', ''file'', ''dropdownlist'', ''combobox'', ''checkbox'', ''label'', ''link'' | | ''type'' | Type of the option or options dialog control. \\ Supported types are: ''textbox'', ''file'', ''dropdownlist'', ''combobox'', ''checkbox'', ''label'', ''link'' |
| ''caption'' | Caption of the options dialog control representing the option. | | ''caption'' | Caption of the options dialog control representing the option. |
-| ''default'' | Default value of the option. \\ For run-time options (those without the ''-config'' switch) of type ''textbox'' and ''file'', non-file [[custom_command#patterns|custom command patterns]] (''!/'', ''!S'', ''!@'', ''!U'', ''!P'', ''!#'' and ''!\'') are expanded. |+| ''default'' | Default value of the option. \\ For run-time options (those without the ''-config'' switch) of type ''textbox'' and ''file'', non-file [[custom_command#patterns|custom command patterns]] (''!/'', ''!E'', ''!S'', ''!@'', ''!U'', ''!P'', ''!#'' and ''!\'') are expanded. |
| ''additional'' | Additional parameters specific to the option type. See below. | | ''additional'' | Additional parameters specific to the option type. See below. |
Line 71: Line 72:
| ''textbox'' | Plain text edit box. The ''default'' defines the default text value. The value of the option equals the value entered into the edit box. | | ''textbox'' | Plain text edit box. The ''default'' defines the default text value. The value of the option equals the value entered into the edit box. |
| ''file'' | File selector. The ''default'' defines the default path. Environment variables in the default value are resolved. The value of the option equals the path selected. | | ''file'' | File selector. The ''default'' defines the default path. Environment variables in the default value are resolved. The value of the option equals the path selected. |
-| ''dropdownlist'' | Dropdown menu. The ''additional'' parameters define a list of possible values with syntax ''[value=]text''. The ''text'' will be displayed in the dropdown menu. The value of the option equals the ''value'' of the selected item. If the ''value='' part is missing, the ''text'' is used as a value. The item with ''value'' equal to the ''default'' will be selected by default. | +| ''dropdownlist'' | Drop-down menu. The ''additional'' parameters define a list of possible values with syntax ''[value=]text''. The ''text'' will be displayed in the drop-down menu. The value of the option equals the ''value'' of the selected item. If the ''value='' part is missing, the ''text'' is used as a value. The item with ''value'' equal to the ''default'' will be selected by default. | 
-| ''combobox'' | Combo box. The ''additional'' parameters define a list of possible values with syntax ''[value=]text''. The ''text'' will be displayed in the dropdown menu. The value of the option equals the ''value'' of the selected item. If the ''value='' part is missing, the ''text'' is used as a value. If a custom text is entered, the value equals to the text. The item with ''value'' equal to the ''default'' will be selected by default. If no such item exists, the ''default'' is used as the default custom text. |+| ''combobox'' | Combo box. The ''additional'' parameters define a list of possible values with syntax ''[value=]text''. The ''text'' will be displayed in the drop-down menu. The value of the option equals the ''value'' of the selected item. If the ''value='' part is missing, the ''text'' is used as a value. If a custom text is entered, the value equals to the text. The item with ''value'' equal to the ''default'' will be selected by default. If no such item exists, the ''default'' is used as the default custom text. |
| ''checkbox'' | Checkbox. Two optional ''additional'' parameters define values of the option, when the checkbox is checked and not checked, respectively. If the ''default'' equals to the first additional parameter, the checkbox is checked by default. | | ''checkbox'' | Checkbox. Two optional ''additional'' parameters define values of the option, when the checkbox is checked and not checked, respectively. If the ''default'' equals to the first additional parameter, the checkbox is checked by default. |
| ''label'' | Text label. Just a plain text label displayed on the options dialog. \\ This "option" has no value. Use ''-'' for the ''name'' parameter. | | ''label'' | Text label. Just a plain text label displayed on the options dialog. \\ This "option" has no value. Use ''-'' for the ''name'' parameter. |
Line 90: Line 91:
# @option      - -config link https://winscp.net/eng/docs/extension#options # @option      - -config link https://winscp.net/eng/docs/extension#options
# @option      Mask -config textbox "&File mask" "*.txt; *.html" # @option      Mask -config textbox "&File mask" "*.txt; *.html"
-# @option      SearchType -config dropdownlist "Search for:" -files -files="Files" -dirs="Directories" -both="Files and Directories"+# @option      SearchType -config dropdownlist "Search for:" -files
 +#                  -files="Files" -dirs="Directories" -both="Files and Directories"
# @option      LogFile -config file "&Log File:" "%APPDATA%\mylog.log" # @option      LogFile -config file "&Log File:" "%APPDATA%\mylog.log"
# @option      Pause -config checkbox "&Pause at the end" -pause -pause # @option      Pause -config checkbox "&Pause at the end" -pause -pause
</code> </code>
-Produce this options dialog:+Produce this options dialog (the [[ui_pref_commands#configure|//Keyboard shortcut// option]] is added implicitly):
&screenshotpict(extension_options) &screenshotpict(extension_options)
Line 102: Line 104:
<code> <code>
-example.exe -Mask="%Mask%" %SearchType% -Log="%LogFile%" %Pause%+example.exe -mask="%Mask%" %SearchType% -log="%LogFile%" %Pause%
</code> </code>
Line 108: Line 110:
<code> <code>
-example.exe -Mask="*.txt; *.html" -files -Log="C:\Users\username\AppData\Roaming\mylog.log" -pause+example.exe -mask="*.txt; *.html" -files -log="C:\Users\username\AppData\Roaming\mylog.log" -pause
</code> </code>
Line 115: Line 117:
These official extensions are deployed by WinSCP installer: These official extensions are deployed by WinSCP installer:
-  * [[extension_generate_http_url|Generate HTTP URL]]; +  * [[extension_generate_http_url|*]]; 
-  * [[library_example_verify_file_checksum|Verify checksum of a remote file against a local file over SFTP/FTP protocol]]; +  * [[extension_compare_files|*]]; 
-  * [[library_example_recursive_search_text|Search recursively for text in remote directory / Grep files over SFTP/FTP protocol]]; +  * [[library_example_verify_file_checksum|*]]; 
-  * [[library_example_zip_and_upload|Pack files to ZIP archive and upload it]]; +  * [[library_example_recursive_search_text|*]]; 
-  * [[library_example_keep_local_directory_up_to_date|Keep local directory up to date]]; +  * [[library_example_zip_and_upload|*]]; 
-  * [[library_example_advanced_rename|Batch rename]]. +  * [[library_example_keep_local_directory_up_to_date|*]]; 
 +  * [[library_example_advanced_rename|*]]; 
 +  * [[extension_synchronize_another_server|*]].
===== [[optional]] Optional Extensions ===== ===== [[optional]] Optional Extensions =====
Line 127: Line 130:
You can install these optional extensions by using their page URL's in the //[[ui_pref_commands#extensions|Add Extension]]// command: You can install these optional extensions by using their page URL's in the //[[ui_pref_commands#extensions|Add Extension]]// command:
-  * [[library_example_find_duplicate_files|Find duplicate files in SFTP/FTP server]]; +  * [[library_example_find_duplicate_files|*]]; 
-  * [[library_example_download_clipboard|Download remote file from a path stored in clipboard]]; +  * [[library_example_download_clipboard|*]]; 
-  * [[library_example_moves_files_keeping_directory_structure#upload_powershell|Recursively move files in directory tree to SFTP/FTP server while preserving source directory structure]]. +  * [[library_example_moves_files_keeping_directory_structure#upload_powershell|*]]; 
 +  * [[library_example_remember_downloaded_files|*]]; 
 +  * [[extension_archive_and_download|*]]; 
 +  * [[library_example_two_way_synchronize_delete|*]].
===== [[loading]] Loading ===== ===== [[loading]] Loading =====
Line 137: Line 142:
  * ''Extension'' subfolder of WinSCP installation folder. This is where WinSCP installer installs the official WinSCP extensions (see above).   * ''Extension'' subfolder of WinSCP installation folder. This is where WinSCP installer installs the official WinSCP extensions (see above).
-  * ''WinSCP.exe'' executable folder. This is handy for a [[portable|portable use]] of WinSCP. Just put your extensions to the same folder (USB drive) as the [[executable|WinSCP executables]].+  * ''WinSCP.exe'' executable folder. This is handy for a [[portable|portable use]] of WinSCP. Just put your extensions to the same folder (USB drive) as the [[executables|WinSCP executables]].
  * ''Extensions'' subfolder of WinSCP application data folder. I.e. ''%APPDATA%\WinSCP\Extensions'', typically ''C:\Users\username\AppData\Roaming\WinSCP\Extensions''. &winpath This is where WinSCP [[ui_pref_commands#extensions|stores the user-installed extensions]].   * ''Extensions'' subfolder of WinSCP application data folder. I.e. ''%APPDATA%\WinSCP\Extensions'', typically ''C:\Users\username\AppData\Roaming\WinSCP\Extensions''. &winpath This is where WinSCP [[ui_pref_commands#extensions|stores the user-installed extensions]].
Line 150: Line 155:
===== Further Reading ===== ===== Further Reading =====
-  * [[guide_custom_commands_automation|Extending WinSCP with Custom commands that run .NET assembly or WinSCP script]].+  * [[guide_custom_commands_automation|*]].

Last modified: by martin