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.1

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

Please Share your Custom Commands here

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.

If you want to have full featured terminal, you may find command Open In PuTTY useful.

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. However you can have even custom command without patterns, just to avoid typing it again every time.

Types of Custom Commands

There are basically four types of custom commands:

  • Remote or local commands that does not work with files. These can be executed any time.
  • Remote commands are executed on the remote servers with the remote files. These commands can modify the files. You need to have selected remote files first to execute the command.
  • 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. You need to have selected remote files first to execute the command.
  • 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).

Executing and Configuring Custom Commands

Custom commands are located in menu File(s) > Custom Commands and also in file context menu. 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.

  1. If you happen to execute command that requires user input, WinSCP will eventually timeout waiting for command to finish and you will need to reconnect your session.Back

Last modified: by 202.152.162.216