If there is a remote command you need to execute regularly and in particular if the command works with files, you may find custom commands useful.
A custom command is a predefined command which can contain several patterns that WinSCP replaces, for example, with names of files selected in a panel (see below). For example, the pre-defined custom command Touch, defined as
touch "!", calls the
touch command on every selected file in the remote panel.
However you can have even custom commands without patterns, just to avoid typing the command again every time.
- Types of Custom Commands
- Patterns Used in Custom Commands
- Executing and Configuring Custom Commands
- Debugging Custom Commands
- Useful Custom Commands
- Distributing Custom Commands as Extensions
There are basically these types of custom commands:
- Remote or local commands that do not work with files. These can be executed any time.
- Remote commands that are executed on remote servers with remote files. These commands can modify the files. You must have remote files selected first in order to execute the command.
- Local commands that are executed on the local machine with remote files downloaded to a temporary folder. You must have remote files selected first in order to execute the command. If the command modifies the files, the changes are uploaded to the server.
- Local commands that are executed on the local machine with paths to a remote files. Such commands will typically operate on the files over their own session (use
!Spattern to pass current session settings to the command). The command may use WinSCP .NET assembly or scripting.
- Local commands that work with local files. The command can work completely with selected local files only. Or it can for example process the local file somehow (e.g. compress them) and upload them to the remote server using own session (again, use the
!Spattern as mentioned previously).
- Special type is a local command that is executed with both local and remote files. This is particularly useful for running “diff” tools. This type is available only with the Commander interface. You can execute these commands on a set of remote files against the the same number of local files (once for each pair). Another option is to execute it on a set of remote files against one local file (once for each remote file) and vice versa.
You can use following patterns in your custom commands:
||Any||Is replaced with exclamation mark (
||Any||File path (a relative path to a root of an operation, when referring to remote file; an absolute path when referring to a local temporary copy of a remote file). Command with the pattern will be executed once for every selected file. In general it should be surrounded with quotes for the command to work with filenames containing spaces. Cannot be combined with pattern
||Any||Quoted, space-delimited list of paths to files (see
||Any||Current remote path. The path always ends with slash.|
||Any||Current session URL. You can use it to pass current session data to another instance of WinSCP (using command-line or scripting command
||Any||Current session hostname.|
||Any||Current session username.|
||Any||Current session password (if stored or remembered).|
||Any||Current session port number.|
||Any||Current session name.|
||Any||When used, user is prompted to enter value that replaces the pattern.
When implementing an extension, use a runtime option instead, as a more flexible alternative.
||Any||Replaced with output of a given local console command.
The command can also be used solely for its side effect, without actually outputting anything.
Limited set of static patterns can be used in
||Local||Full path to a local file. In general it should be used in a combination with
||Local||Current local path. The path never ends with backslash.|
The custom command is executed for files selected in file panel. It can be optionally executed also for selected directories or for files in selected directories (or both).
Custom commands that do not operate with files are located in menu Commands > Static Custom Commands, and on special Custom Command toolbar.
Custom commands can be configured in Preferences.
You may eventually want to execute ad hoc custom command, without predefining it first. To do so, go to File(s) > Custom Commands > Enter. To repeat the last ad hoc custom command, go to File(s) > Custom Commands > Last.
If you want to test how the patterns in the custom command are expanded, hold down
Ctrl keys, while executing the custom command. The command, with all patterns replaced, will get copied to the clipboard, instead of getting executed.
You can see list of custom commands other users found useful.
A custom command can be distributed and installed in a form of a WinSCP extension file.