This is an old revision of the document!
Remote/Custom Commands
WinSCP offers unique feature to execute command on remote server as with regular SSH terminal client. However as it does not implement the terminal fully, you can execute only commands that does not require user input.
Basically the feature is supported only for SCP protocol. With SFTP you can still use the feature by opening separate shell session, which in fact takes place automatically for you.
Advertisement
How to Enter the Remote Command
You can enter the command on Console window (Commands > Open Terminal).
If you are using Norton Commander interface you can also enter the command on command-line box below the panels.
Custom Commands
If there is command you need to execute regularly and in particular if the command works with files, you can find custom commands useful.
The custom command is predefined command, which can contain several patterns, which WinSCP replaces for example with names of files selected in panel, see below. For example pre-defined custom command Touch, defined as touch “!”
, calls touch
command on every selected file in remote panel.
Types of Custom Commands
There are basically three types of custom commands:
- Remote commands are executed on the remote servers with the remote files. These commands can modify the files.
- Local commands are executed on the local machine with the remote files downloaded to temporary folder. It makes no sense for the command to modify the files, because they are not uploaded back after the command finishes.
- Special type is local command that is executed both with local and remote files. This is particuarly useful for running “diff” tools. This type is available only with Norton Commander interface. You can execute such command for set of remote files against the the same number or local files (once for each pair). Another option is to execute it for set of remote files against one local file (once for each remote file) and vice versa.
Advertisement
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 recursivelly. |
!?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. |
!^! |
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 recursivelly. |
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 are located in menu File(s) > Custom Commands and also in file context menu. Custom commands can be configured in Preferences.