Differences
This shows you the differences between the selected revisions of the page.
remote_command 2005-06-06 | remote_command 2023-02-22 (current) | ||
Line 1: | Line 1: | ||
- | ====== Remote/Custom Commands ====== | + | ====== Remote 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. ((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.)) | + | WinSCP offers a unique feature to execute commands on a remote server as with a regular terminal client. However as it cannot implement the terminal fully, there are some limitations. Particularly, you cannot execute commands that require terminal emulation or user input. See [[#limitations|below]] for technical details. |
- | Basically the feature is supported only for [[protocols|SCP protocol]]. With SFTP you can still use the feature by opening [[shell_session|separate shell session]], which in fact takes place automatically for you. | + | Basically, the feature is supported only for [[scp|SCP protocol]]. With [[SFTP]] you can still use the feature by opening [[shell_session|separate shell session]], which in fact takes place automatically for you. With [[FTP]] you can only execute FTP protocol commands. However, some FTP servers have a command allowing execution of remote commands, e.g. ''SITE EXEC <command>''. [[WebDAV]] and [[S3]] protocols do not allow executing remote commands. |
===== How to Enter the Remote Command ===== | ===== How to Enter the Remote Command ===== | ||
You can enter the command on [[ui_console|Console window]] (//Commands > Open Terminal//). | You can enter the command on [[ui_console|Console window]] (//Commands > Open Terminal//). | ||
- | If you are using Norton Commander interface you can also enter the command on [[ui_commander#command_line|command-line box]] below the panels. | + | If you are using the Commander interface you can also enter the command on [[ui_commander#command_line|command-line box]] below the panels. |
- | If you want to have full featured terminal, you may find command //[[integration_app#opening_current_session_in_putty|Open In PuTTY]]// useful. | + | If you want to have full featured terminal, you may find command //[[integration_putty#open_putty|Open in PuTTY]]// useful. |
+ | |||
+ | ===== Automating Command Execution ===== | ||
+ | To automate remote command execution use scripting command ''[[scriptcommand_call|call]]'' or .NET assembly method ''[[library_session_executecommand|Session.ExecuteCommand]]''. | ||
===== Custom Commands ===== | ===== 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. | + | If there is a command you need to execute regularly and in particular if the command works with files, you can find [[custom_command|custom commands]] useful. |
- | + | ||
- | The custom command is [[ui_pref_commands|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 [[temp_folders|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 [[ui_commander|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. | + | |
- | + | ||
- | ==== 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 [[ui_file_panel|file panel]]. It can be optionally executed also for selected directories or for files in selected directories (or both). | + | ===== [[limitations]] Technical Background of Terminal Limitations ===== |
+ | WinSCP does not support commands that require terminal emulation or user input. | ||
- | ==== Executing and Configuring Custom Commands ==== | + | Terminal emulation cannot be implemented at all as it is not possible to combine terminal emulation and file transfers in the same session. The reason is that with terminal emulation control characters have a special meaning that is interpreted by the server. On the other hand, the same characters (bytes) have special meaning in the file transfer protocols or may simply be present in the (binary) files being transferred. |
- | Custom commands are located in menu //File(s) > Custom Commands// and also in file [[ui_context_menu|context menu]]. Custom commands can be configured in [[ui_pref_commands|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//. | + | If you happen to try to execute a command requiring terminal emulation, it will typically refuse to run with an error message like "Error opening terminal", "No TTY available", "stdin: is not a tty" or "Couldn't open /dev/tty for reading". |
- | ==== Useful Custom Commands ==== | + | WinSCP may possibly support user input. However, most commands requiring user input does that via terminal emulation features. If your command needs plain input without terminal emulation you can use input redirection like: |
- | You can see list of [[custom commands]] other users found useful. | + | <code bash> |
+ | echo "some input" | command | ||
+ | </code> |