Differences

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

scripting 2022-02-01 scripting 2025-11-06 (current)
Line 5: Line 5:
Using scripting interface directly is recommended for simple tasks not requiring any control structures. For complex tasks, using [[library|WinSCP .NET assembly]] is preferred. Using scripting interface directly is recommended for simple tasks not requiring any control structures. For complex tasks, using [[library|WinSCP .NET assembly]] is preferred.
 +
 +~~AD~~
&screenshotpict(scripting) &screenshotpict(scripting)
Line 21: Line 23:
Note that the first connection to an SSH server requires [[#hostkey|verification of the host key]]. Note that the first connection to an SSH server requires [[#hostkey|verification of the host key]].
Also the first connection to FTPS or WebDAVS host with [[tls#certificate|certificate]] signed by untrusted authority requires verification of the certificate. Also the first connection to FTPS or WebDAVS host with [[tls#certificate|certificate]] signed by untrusted authority requires verification of the certificate.
 +
 +~~AD~~
===== [[result]] Checking Results ===== ===== [[result]] Checking Results =====
Line 68: Line 72:
The optional ''rel'' part, with syntax ''[-+]time[YDHNS]'', produces past (''-'') or future (''+'') timestamps. One of the following units must be used: ''Y'' (years), ''D'' (days), ''H'' (hours), ''N'' (minutes) or ''S'' (seconds). For example, the ''%TIMESTAMP-1D#yyyy-mm-dd%'' (the ''-1D'' meaning one day in the past) resolves to ''2016-06-21'' on 22 June 2016. The optional ''rel'' part, with syntax ''[-+]time[YDHNS]'', produces past (''-'') or future (''+'') timestamps. One of the following units must be used: ''Y'' (years), ''D'' (days), ''H'' (hours), ''N'' (minutes) or ''S'' (seconds). For example, the ''%TIMESTAMP-1D#yyyy-mm-dd%'' (the ''-1D'' meaning one day in the past) resolves to ''2016-06-21'' on 22 June 2016.
-To use ''<nowiki>%TIMESTAMP...%</nowiki>'' on a command-line in a batch file, you need to escape the ''%'' by doubling it to ''<nowiki>%%TIMESTAMP...%%</nowiki>'', to avoid a batch file interpreter trying to resolve the variable.+To use ''<nowiki>%TIMESTAMP...%</nowiki>'' on a command-line in a ==?timestamp_batch== batch file, you need to escape the ''%'' by doubling it to ''<nowiki>%%TIMESTAMP...%%</nowiki>'', to avoid a batch file interpreter trying to resolve the variable.
==== [[arguments]] Script Arguments ==== ==== [[arguments]] Script Arguments ====
Line 159: Line 163:
<code winscp> <code winscp>
# Connect # Connect
-open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx...="+open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx..."
# Change remote directory # Change remote directory
cd /home/user cd /home/user
Line 184: Line 188:
For simple scripts you can specify all the commands on [[commandline|command-line]] using ''/command'' switch: For simple scripts you can specify all the commands on [[commandline|command-line]] using ''/command'' switch:
<code batch> <code batch>
-winscp.com /ini=nul /command "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxx...=""" "get examplefile.txt d:\" "exit"+winscp.com /ini=nul /command "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxx...""" "get examplefile.txt d:\" "exit"
</code> </code>
Line 191: Line 195:
<code batch> <code batch>
winscp.com /ini=nul /command ^ winscp.com /ini=nul /command ^
-    "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxx...=""" ^+    "open sftp://user:password@example.com/ -hostkey=""ssh-rsa 2048 xxxxxxxxxxx...""" ^
    "get examplefile.txt d:\" ^     "get examplefile.txt d:\" ^
    "exit"     "exit"

Last modified: by 186.22.56.147