Differences

This shows you the differences between the selected revisions of the page.

commandline 2009-01-17 commandline 2024-12-16 (current)
Line 1: Line 1:
====== Command-line Options ====== ====== Command-line Options ======
-If you are going to run WinSCP from command-line often, you may wish to add WinSCP installation directory to [[integration#search_path|search path]]. 
-<code> + 
-winscp.exe stored_session + 
-winscp.exe [(sftp|ftp|scp)://][user[:password]@]host[:port][/path/[file]+===== [[parameters]] Parameters ===== 
-winscp.exe [session] [/console] [/script=script_file] [/command command1 command2 ...] +Parameters for ''[[executables|winscp.exe]]'' executable: 
-winscp.exe [session] /synchronize [local_directory] [remote_directory] [/defaults+&amp;amp;lt;code batch&amp;amp;gt; 
-winscp.exe [session] /keepuptodate [local_directory] [remote_directory] [/defaults+winscp.exe site|workspace|folder 
-winscp.exe [session] /upload file1 file2 file3 ... [/defaults+winscp.exe &amp;amp;lt;session_url&amp;gt;[/path/[file]
-winscp.exe [session] [/privatekey=<key_file>] [/hostkey=<fingerprint>] +winscp.exe [mysession] [/sessionname=&amp;lt;name&amp;gt;] 
-winscp.exe /ini=<inifile> /log=<logfile>+winscp.exe [mysession] [/newinstance] 
 +winscp.exe [mysession] /edit &amp;lt;path&amp;gt; 
 +winscp.exe [mysession] /browse[=&amp;lt;file&amp;gt;
 +winscp.exe [mysession] /synchronize [local_directory] [remote_directory] [/defaults[=secs]
 +winscp.exe [mysession] /keepuptodate [local_directory] [remote_directory] [/defaults[=secs]
 +winscp.exe [mysession] /refresh [path] 
 +winscp.exe [mysession] /upload file1 file2 file3 ... [/defaults[=secs]
 +winscp.exe [mysession] [/privatekey=&amp;lt;file&amp;gt; [/passphrase=&amp;lt;passphrase&amp;gt;]
 +winscp.exe [mysession] [/hostkey=&amp;lt;fingerprint&amp;gt;
 +winscp.exe [mysession] [/username=&amp;lt;user&amp;gt;] [/password=&amp;lt;pass&amp;gt;] 
 +winscp.exe [mysession] [/passwordsfromfiles
 +winscp.exe [mysession] [/clientcert=&amp;lt;file&amp;gt; [/passphrase=&amp;lt;passphrase&amp;gt;]] 
 +winscp.exe [mysession] [/certificate=&amp;lt;fingerprint&amp;gt;] 
 +winscp.exe [mysession] [/passive[=on|off]] [/implicit|explicit] 
 +winscp.exe [mysession] [/timeout=&amp;lt;sec&amp;gt;] 
 +winscp.exe [mysession] [/rawsettings setting1=value1 setting2=value2 ...] 
 +winscp.exe [/console] [/script=&amp;lt;script_file&amp;gt;] [/command command1 command2 ...] 
 +          [/parameter // param1 ...
 +winscp.exe [/log=&amp;lt;logfile&amp;gt;  [/loglevel=&amp;lt;level&amp;gt;] [/logsize=[&amp;amp;lt;count&amp;amp;gt;*]&amp;lt;size&amp;gt;]] 
 + ··········[/xmllog=&amp;amp;lt;logfile&amp;amp;gt; [/xmlgroups]
 +winscp.exe [/ini=&amp;amp;lt;inifile&amp;amp;gt;
 +winscp.exe [/rawconfig config1=value1 config2=value2 ...] 
 +winscp.exe [/rawtransfersettings setting1=value1 setting2=value2 ...] 
 +winscp.exe /batchsettings &amp;amp;lt;site_mask&amp;amp;gt; setting1=value1 setting2=value2 ... 
 +winscp.exe /keygen keyfile [/output=&amp;lt;file&amp;gt;] [/changepassphrase] 
 +winscp.exe /keygen keyfile [/comment=&amp;lt;text&amp;gt;] [/certificate=&amp;lt;file&amp;gt;]
winscp.exe /update winscp.exe /update
 +winscp.exe /info
winscp.exe /help winscp.exe /help
 +&amp;lt;/code&amp;gt;
 +
 +Parameters for ''[[executables|winscp.com]]'' executable:
 +&amp;lt;code batch&amp;gt;
 +winscp.com [/script=script_file] [/command command1 command2 ...]
 +          [/parameter // param1 ...]
 +winscp.com [/stdout[=binary|chunked]] [/stdin]
 +winscp.com [/log=&amp;lt;logfile&amp;gt; [/loglevel=&amp;lt;level&amp;gt;] [/logsize=[&amp;lt;count&amp;gt;*]&amp;lt;size&amp;gt;]]
 +          [/xmllog=&amp;lt;logfile&amp;gt; [/xmlgroups]] [/nointeractiveinput]
 +winscp.com [/ini=&amp;lt;inifile&amp;gt;]
 +winscp.com [/rawconfig config1=value1 config2=value2 ...]
 +winscp.com /batchsettings &amp;lt;site_mask&amp;gt; setting1=value1 setting2=value2 ...
 +winscp.com /keygen keyfile [/output=&amp;lt;file&amp;gt;] [/changepassphrase]
 +winscp.com /keygen keyfile [/comment=&amp;lt;text&amp;gt;] [/certificate=&amp;lt;file&amp;gt;]
 +winscp.com /info
 +winscp.com /help
 +&amp;lt;/code&amp;gt;
 +
 +
 +==== [[session]] Session ====
 +The first syntax opens the [[session_configuration#site|site]]. To open site, stored in folder, use path syntax "folder/site". You can also open [[workspace|workspace]] or all sites in site folder.
 +
 +The second creates the session specified by [[session_url|session URL]] and optionally by initial remote path. If the remote path is not ended by slash (''/''), it is treated as path to file (or even directory) that should be [[task_download#url|downloaded]].
 +
 +The parameter ''/==sessionname=='' specifies a custom name of the session to be used instead of the automatically generated name in a format ''username@hostname'' or to override the name of the saved site.
 +
 +If there's already an idle WinSCP instance running, the session(s) opens in the existing instance. To force the session to open in a new instance of WinSCP, use ''/==newinstance=='' parameter. If no session is specified on command-line, [[ui_login|Login dialog]] opens to select one.
 +
 +The parameter ''/==privatekey=='' specifies a [[local_path|local path]] to an [[public_key#private|SSH private key file]]. If the key file is encrypted, use the ''/passphrase'' to specify its passphrase. The passphrase [[#passwordsfromfiles|can be read from a file]].
 +
 +The parameter ''/hostkey'' specifies the fingerprint of the expected SSH host key (or several alternative fingerprints separated by a semicolon). It makes WinSCP automatically [[ssh_verifying_the_host_key|accept the host key]] with the fingerprint.
 +
 +You can use the parameters ''/==username=='' and ''/password'' as an alternative way to specify the credentials.  The credentials are normally part of the [[session_url|session URL]]. Using these switches has the advantage of not needing to [[session_url#special|URL-encode special characters]]. The password [[#passwordsfromfiles|can be read from a file]].
 +
 +With parameter ''/==passwordsfromfiles=='', the values of [[#username|''/password'']], [[#privatekey|''/passphrase'']] and in general all passwords from all sources are interpreted as paths to files, where the actual passwords are read from. The files must use UTF-8 or UTF-16 encoding.((With UTF-8 encoding use of BOM is optional. With UTF-16 the BOM is mandatory. Only the first line of the file is considered. Use of more lines is reserved for the future.))
 +
 +The parameter ''/clientcert'' specifies a [[local_path|local path]] to FTPS or WebDAVS [[tls#client_certificate|TLS/SSL client certificate]]. If the certificate is encrypted, use the ''/passphrase'' to specify its passphrase.
 +
 +When a FTPS or WebDAVS server [[tls#certificate|TLS/SSL certificate]] is not trusted (typically a self-signed certificate), use the parameter ''/certificate'' to specify the fingerprint of the untrusted certificate. It makes WinSCP trust the certificate. Several alternative fingerprints can be separated by a semicolon.
 +
 +The parameter ''/passive'' enables a [[ui_login_connection#connection|passive]] (''=on'') or an active (''=off'') transfer mode ([[FTP]] protocol only).
 +
 +The parameters ''/implicit'', and ''/explicit'' enable respective [[ftps#methods|method of invoking FTPS]].
 +
 +The parameter ''/timeout'' specifies [[ui_login_connection#timeout|server response timeout]].
 +
 +The parameter ''/==rawsettings=='' allows configuring any site settings [[rawsettings|using raw format as in an INI file]]. E.g. to enable an SSH compression and an agent forwarding, use ''/rawsettings Compression=1 AgentFwd=1''. The parameter must come after the session URL (if any).
 +
 +When using [[scripting]], use the ''[[scriptcommand_open|open]]'' command (and its switches) instead.
 +
 +Examples:
 +
 +<code batch>
 +winscp.exe "My site"
 +winscp.exe sftp://martin:password@example.com/ /hostkey="ssh-rsa 2048 xxxxxxxxxxx..."
 +winscp.exe scp://test@example.com:2222/ /privatekey=mykey.ppk
 +winscp.exe ftps://martin:password@example.com/
</code> </code>
-The first syntax opens the stored session (to open session, stored in folder, use path syntax &quot;folder/session"). The second creates the session specified by at least hostname, optionally by name of protocol, port number, username, password and initial remote path. If the remote path is not ended by slash (''/''), it is treated as path to file (or even directory) that should be downloaded. Special characters (like ''@'' in username) can be encoded using ''%XX'' syntax, where ''XX'' is hexadecimal ASCII code.+==== [[logging]] Logging ====
-Parameter ''/console'' executes WinSCP in [[scripting|console (scripting) mode]]. Note that when WinSCP is executed via [[scripting#console|console interface (winscp.com)]], the ''/console'' parameter is not necessary. +With ''/log'' parameter you may turn on [[logging|session logging]] to file specified by [[local_path|local path]]. In the path you can use the same patterns as in the [[ui_pref_logging#session_log|logging preferences]].
-To run batch script either pass script file using ''/script'' parameter or specify the commands directly on command line using ''/command''. In the latter case each following parameter is treated as single command (If the command includes spaces, enclose it in quotes). If both ''/script'' and ''/command'' parameters are used, commands from script file are executed first. When the last command is not ''exit'', regular non-batch mode follows. If ''/console'' parameter is not used along with ''/script'' or ''/command'', the script/command is executed without visual feedback (window).+Use parameter ''/==loglevel=='' to change logging level. The value can be in range ''-1''...''2'' (for //Reduced//, //Normal//, //Debug 1// and //Debug 2// logging levels respectively). Append additional ''*'' to enable password logging (e.g. ''/loglevel=2*'').((Append ''*-'' to disable password logging.))
-With ''/synchronize'' or ''/keepuptodate'' parameter WinSCP performs //Synchronize// or //Keep remote directory up to date// commands respectively on the specified session and directories. A dialog to set options is displayed first (Note that this is not intended for automation, see [[scripting]]).+Use parameter ''/==logsize=='' to configure log file size limit and log file rotation. Specify maximum size in bytes, optionally with ''K'', ''M'' or ''G'' units. Optionally you can limit number of archived log files using ''count*'' prefix. For example ''/logsize=5*10M'' will limit log file size to 10 MB and will allow up to 5 archived logs.
-With ''/upload'' parameter WinSCP uploads specified files to remote directory of session defined using one of the previous syntaxes. A dialog to set options is displayed first (Note that this is not intended for automation, see [[scripting]], but to allow [[integration#exporer_s_send_to_context_menu|Windows Explorer's 'Send To' menu]] integration).+<code batch&gt; 
 +winscp.exe sftp://martin@example.com/ /log=&quot;C:\winscp.log&quot; /loglevel=0 
 +&lt;/code>
-Use ''/defaults'' parameter along with ''/upload'', ''/synchronize'' or ''/keepuptodate'' to skip the settings dialog and start the operation straight away with default settings.+With ''/xmllog'' parameter you may turn on [[logging_xml|XML logging]] to file specified by local path. ((For backward compatibility, XML logging can also be enabled using ''/log'' parameter with filename ending with ''.xml'' extension.)) In the path you can use the same patterns as in the [[ui_pref_logging#session_log|logging preferences]].
-Parameter ''/privatekey'' specifies [[public_key#private|private key file]]. Parameter ''/hostkey'' specifies fingerprint of expected host key (or several fingerprints separated by semicolon). It makes WinSCP automatically [[ssh#verifying_the_host_key|accept hostkey]] with the fingerprint. +Use parameter ''/xmlgroups'' along with ''/xmllog'', to [[logging_xml#group|group]] all XML log elements belonging to the same command under parent ''group'' element.
-With ''/ini'' parameter you may specify path to [[config|configuration INI file]]. It effectively disables using [[config|registry as configuration storage]]. If the file does not exist, default configuration will be used and the file will be created. You can use environment variables in the path, with syntax ''%NAME%''. 
-With ''/log'' parameter you may turn on session logging to given file. You can use environment variables in the path, with syntax ''%NAME%''.+==== [[scripting]] Console/scripting mode ==== 
 +Parameter ''/console'' executes WinSCP in [[scripting|console (scripting) mode]]. Note that when using ''[[executables|winscp.com]]'', the console mode is implicit, so using ''/console'' parameter is redundant.·
 +To run batch script either pass script file using ''/script'' parameter or specify the commands directly on command line using ''/command''. In the latter case each following parameter is treated as single command. See [[#syntax|syntax section]] and examples below for details how to deal with spaces and double-quotes.
 +
 +If both ''/script'' and ''/command'' parameters are used, commands from script file are executed first. When the last command is not ''[[scriptcommand_exit|exit]]'', regular non-batch mode follows.
 +
 +Use parameter ''/parameter'' to specify list of arguments to be [[scripting#arguments|passed to script]]. It is recommended to escape the arguments with [[#syntax|''//'' switch]].
 +
 +With ''[[executables|winscp.exe]]'', if ''/console'' parameter is not used along with ''/script'' or ''/command'', the script/command is executed without visual feedback (window).
 +
 +Use the parameter ''/==stdout=='' to enable ==stream==ing files to the [[executables#redirection|standard output of ''winscp.com'']]. When the parameter is used, the [[scriptcommand_get|''get'' command]] will stream the downloaded file(s) to the standard output, when ''-'' is used as a download target. By default (or with the ''binary'' flag), the files are streamed unmodified. With the ''chunked'' flag, the files are individually encoded using [[https://en.wikipedia.org/wiki/Chunked_transfer_encoding|Chunked transfer encoding]], what allows separating contents of multiple streamed files. When the parameter is used, all console output that would normally be printed to the standard output is redirected to the error output. Streaming is supported with the [[sftp|SFTP]] and [[ftp|FTP]] protocols only.
 +
 +Use the parameter ''/==stdin=='' to enable streaming files from the [[executables#redirection|standard input of ''winscp.com'']]. When the parameter is used, the [[scriptcommand_put|''put'' command]] will stream the standard input to the remote server, when ''-'' is used as an upload source. Implies [[#nointeractiveinput|''/nointeractiveinput'']]. Streaming is supported with the SFTP and FTP protocols only.
 +
 +Use parameter ''/==nointeractiveinput=='', when feeding commands to ''[[executables|winscp.com]]'' using [[executables#redirection|standard input]], to make sure prompts for anything other than commands (such as password prompts) are cancelled. Also prevents error message popping up when fatal error occurs while starting WinSCP. When combined with ''/xmllog'' the fatal error is recorded in the %%XML%% log.
 +
 +Examples: <code batch>
 +winscp.com /script="C:\Users\martin\Documents\myscript.txt"
 +winscp.com /command "open sftp://martin@example.com/ -hostkey=""ssh-rsa 2048 xxxx...""" "exit"
 +winscp.exe /console /script="myscript.txt" /log="myscript.log"
 +</code>
 +
 +You can have WinSCP [[ui_generateurl|generate a scripting command-line for you]].
 +
 +==== [[operations]] Operations ====
 +The following parameters can be used to create a shortcut that initiates operation in GUI mode. They are not intended for automation, for that see [[scripting]].
 +
 +Use ''/==edit=='' to open a remote file in WinSCP [[ui_editor|internal editor]].
 +
 +Use ''/browse'' to select the specified file in (both) [[ui_file_panel|file panel(s)]]. The switch can also be used together with a [[session_url#file|file URL]] for the same effect, overriding the default [[task_download#url|download action]].
 +
 +With ''/==synchronize=='' or ''/keepuptodate'' parameter WinSCP performs //Synchronize// or //Keep remote directory up to date// commands respectively on the specified session and directories. A dialog to set options is displayed first.
 +
 +With ''/upload'' parameter WinSCP uploads specified files to initial remote directory of session.((Parameter is primarily intended to allow [[integration#send_to|Windows File Explorer's 'Send To' menu]] integration.)) A dialog to set options is displayed first.
 +
 +Use ''/==defaults=='' parameter along with ''/upload'', ''/synchronize'' or ''/keepuptodate'' to skip the settings dialog and start the operation straight away with default settings. Alternatively you can specify a number of seconds, to actually show the settings dialogs, but have them automatically submit after the specified time elapses.
 +
 +Use the ''/==refresh=='' parameter to reload remote panel of all running instances of WinSCP. If a session is specified on command-line, only instances that have that session as active are refreshed. If a path is specified after the ''/refresh'', only that directory is refreshed.
 +
 +It is recommended to escape the arguments with [[#syntax|// switch]].
 +
 +Example: <code batch>
 +winscp.exe /defaults /synchronize // "C:\Users\martin\Documents\MySite" /home/martin/public_html
 +</code>
 +
 +==== [[configuration]] Configuration ====
 +With ''/ini'' parameter you may specify [[local_path|local path]] to [[config|configuration INI file]]. It effectively disables using registry as [[config|configuration storage]]. If the file does not exist, default configuration will be used and the file will be created.
 +
 +<code batch>
 +winscp.exe /ini="C:\Users\martin\Documents\myconfig.ini"
 +</code>
 +
 +Use ''nul'' instead of path to force WinSCP start with its [[config#no|default configuration and not save the configuration on exit]].
 +
 +With ''/==rawconfig=='' parameter you can set any configuration settings [[rawconfig|using raw format as in an INI file]]. E.g. to configure an external IP address use ''/rawconfig Interface\ExternalIpAddress=198.51.100.10''. The parameter must come after a session URL (if any). The configuration set this way is preserved.
 +
 +With ''/==rawtransfersettings=='' you can set any transfer settings [[rawtransfersettings|using raw format as in an INI file]]. E.g. to enable preserving of directory timestamps, use ''/rawtransfersettings PreserveTimeDirs=1''. The configuration set this way is preserved. In [[scripting]], it is better to use ''-rawtransfersettings'' switch of individual scripting commands, like ''get'', ''put'', etc.
 +
 +==== [[batchsettings]] Mass-modification of sites ====
 +
 +Use ''/batchsettings'' to mass-modify stored sites. The first argument is a mask to select sites to modify. Use a syntax of [[file_mask#basic|basic file masks]]. You can also use [[file_mask#path|path mask]] to select sites based on their folders. The other arguments define new values for site settings. Use the same syntax as for ''[[commandline#rawsettings|/rawsettings]]''.
 +
 +For example to configure a proxy for all sites in a "clients" folder, use:
 +
 +<code batch>
 +winscp.exe /batchsettings clients/* ProxyMethod=3 ProxyHost=proxy
 +</code>
 +
 +==== [[keygen]] Private key conversion and modification ====
 +
 +Use the ''/keygen'' switch to convert [[public_key#private|private keys]] from other formats to a PuTTY ''.ppk'' format or to change their passphrase or comment or to add a certificate. You can combine a conversion and key changes into one command.
 +
 +A parameter after the ''/keygen'' switch specifies a path to an input private key file. The input key can be in OpenSSH or ssh.com format (when converting the key to the PuTTY format) or in the PuTTY format (when modifying the key).
 +
 +When converting the key from other format, you need to specify an output key path using the ''/output'' switch. When modifying a PuTTY key, the existing file is overwritten, if ''/output'' is not specified.
 +
 +Use ''/changepassphrase'' switch to change the key passphrase.
 +
 +Use ''/comment'' switch to change the key comment.
 +
 +Use ''/certificate'' switch to add an certificate to the key.
 +
 +For example, to convert key ''mykey.pem'' from OpenSSH format to ''mykey.ppk'' in PuTTY format and set its comment:
 +
 +<code batch>
 +winscp.com /keygen mykey.pem /output=mykey.ppk /comment="Converted from OpenSSH format"
 +</code>
 +
 +To change the passphrase of existing ''mykey.ppk'':
 +
 +<code batch>
 +winscp.com /keygen mykey.ppk /changepassphrase
 +</code>
 +
 +For a compatibility with *nix ''[[https://manpages.debian.org/stable/putty-tools/puttygen.1.en.html|puttygen]]'', the ''-o'', ''-P'', ''-C'', ''%%--old-passphrase%%'' and ''%%--certificate%%'' switches are understood as aliases to ''/output'', ''/changepassphrase'', ''/comment'', ''/passphrase'' and ''/certificate'' respectively. The ''%%--new-passphrase%%'' is recognized too. So, for features supported by WinSCP, you can use the same arguments as for ''puttygen'', just prefixed with ''/keygen'':
 +
 +<code batch>
 +winscp.com /keygen mykey.pem -o mykey.ppk -C "Converted from OpenSSH format"
 +</code>
 +
 +==== [[auxiliary]] Auxiliary ====
When run with ''/update'' parameter, WinSCP only checks for its [[updates|updates]]. When run with ''/update'' parameter, WinSCP only checks for its [[updates|updates]].
 +
 +The parameter ''/==info=='' lists the supported [[ssh_algorithms|SSH]] and [[tls_ciphersuites|TLS/SSL algorithms]].
Parameter ''/help'' shows usage (overview similar to this). Parameter ''/help'' shows usage (overview similar to this).
-For security reasons, when protocol (''%%sftp://%%'', ''%%ftp://%%'' or ''%%scp://%%'') is provided on command line (possible execution from web browser/Windows Explorer), all command-like parameters that cause any automatic action are ignored, including ''/defaults'', ''/log'', ''/script'' and ''/command''.+===== [[syntax]] Syntax ===== 
 +Command-line parameters that include space(s) must be surrounded by double-quotes: 
 +<code batch> 
 +winscp.exe /ini="C:\Users\martin\Documents\myconfig.ini" 
 +</code> 
 + 
 +To use the double-quote as a literal, use two double-quotes sequentially. For example, the ''/command'' expects that each script command is surrounded by double quotes, so that it is passed as a single command-line argument. In addition, any script command argument that includes spaces is expected to be surrounded by double-quotes within the command (see [[scripting#quotes|doubling double-quotes]]): 
 +<code batch> 
 +winscp.com /command "open sftp://... -hostkey=""ssh-rsa ...""" "put ""C:\my file.dat""" 
 +                    <-          Script command 1          -> <-  Script command 2  -> 
 +</code> 
 + 
 +When executing such command from PowerShell, you additionally have to escape the doubled inner double-quotes with ''`'' (backtick) to prevent PowerShell from interpreting them on its own:((Alternative way is using single quotes instead of outer double quotes.)) 
 + 
 +<code batch> 
 +winscp.com /command "open sftp://... -hostkey=`"`"ssh-rsa ...`"`"" "put `"`"C:\my file.dat`"`"" 
 +                    <-            Script command 1            -> <-    Script command 2    -> 
 +</code> 
 + 
 + 
 +To debug the quoting, enable session logging on level //Debug 1// (''/loglevel=1''). The log will show how WinSCP understands your command-line. 
 + 
 +An argument that begins with a slash is considered a switch. To pass a parameter that itself starts with the slash in its syntax (i.e. a remote path like ''/root''), use the special switch ''%%//%%'' (==two slashes==%%)%% before the argument. The switch ''%%//%%'' denotes that all following arguments are not switches. Example: 
 +<code batch> 
 +winscp.exe /synchronize // &quot;C:\Users\martin\Documents\MySite" /root 
 +</code> 
 + 
 +===== Executables ===== 
 +Learn about two [[executables|WinSCP executables]], ''winscp.exe'' and ''winscp.com''. 
 + 
 +===== Hint ===== 
 +If you are going to run WinSCP from command-line often, you may wish to add WinSCP installation directory to [[integration#search_path|search path]]. 
 + 
 +===== [[bash]] Running from Bash ===== 
 +When running WinSCP from a shell, where ''/switch'' is interpreted as a path, such as Git Bash, use a dash (''-'') instead of the slash (''/'') for switches. For example: 
 + 
 +<code batch> 
 +./WinSCP.com -script="myscript.txt" -log="myscript.log" 
 +</code>

Last modified: by martin