Differences

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

2011-03-18 2011-03-18
no summary (92.86.154.166) (hidden) Restored revision 1297668946. Undoing revision 1300460123. (martin) (hidden)
Line 1: Line 1:
-317 
- 
====== Scripting/Automation ====== ====== Scripting/Automation ======
//This article contains detailed description of scripting/automation functionality. You may want to see [[guide_automation|simplified guide]] to the functionality instead.// //This article contains detailed description of scripting/automation functionality. You may want to see [[guide_automation|simplified guide]] to the functionality instead.//
Line 6: Line 4:
In addition to [[interfaces|graphical interface]], WinSCP offers scripting/console interface with many [[script_commands|commands]]. The commands can be typed in interactively, or read from script file or another source. In addition to [[interfaces|graphical interface]], WinSCP offers scripting/console interface with many [[script_commands|commands]]. The commands can be typed in interactively, or read from script file or another source.
-&screenshotpict(scripting)+&screenshotpict(scripting)
===== Using Scripting ===== ===== Using Scripting =====
Line 70: Line 68:
===== Example ===== ===== Example =====
The example below connects to ''example.com'' server with account ''user'', downloads file and closes the session. Then it connects to the same server with the account ''user2'' and uploads the file back. The example below connects to ''example.com'' server with account ''user'', downloads file and closes the session. Then it connects to the same server with the account ''user2'' and uploads the file back.
-&amp;lt;code winscp&amp;gt;+<code winscp>
# Automatically answer all prompts negatively not to stall # Automatically answer all prompts negatively not to stall
# the script on errors # the script on errors
Line 98: Line 96:
# Exit WinSCP # Exit WinSCP
exit exit
-&amp;lt;/code&amp;gt;+</code>
Save the script to the file ''example.txt''. To execute the script file use the following command. As the script connects the session itself, using the command ''open'', omit the ''session'' command-line parameter. Save the script to the file ''example.txt''. To execute the script file use the following command. As the script connects the session itself, using the command ''open'', omit the ''session'' command-line parameter.
-&amp;lt;code&amp;gt;+<code>
winscp.exe /console /script=example.txt winscp.exe /console /script=example.txt
-&amp;lt;/code&amp;gt;+</code>
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:
-&amp;lt;code&amp;gt; +<code> 
-winscp.exe /console /command &amp;quot;option batch on&amp;quot; &amp;quot;open user@example.com&amp;quot; &amp;quot;get examplefile.txt d:\&amp;quot; &amp;quot;exit&amp;quot; +winscp.exe /console /command "option batch on" "open user@example.com" "get examplefile.txt d:\" "exit" 
-&amp;lt;/code&amp;gt;+</code>
Instead of using ''open'' command you can also open a session using a [[commandline|command-line parameter]]. Note that in that case session is opened yet before script starts. Particularly ''option'' commands do not apply yet. Generally you should avoid using this method. Instead of using ''open'' command you can also open a session using a [[commandline|command-line parameter]]. Note that in that case session is opened yet before script starts. Particularly ''option'' commands do not apply yet. Generally you should avoid using this method.
-&amp;lt;code&amp;gt;+<code>
winscp.exe /console /script=example.txt user@example.com winscp.exe /console /script=example.txt user@example.com
-&amp;lt;/code&amp;gt;+</code>
===== Further Reading ===== ===== Further Reading =====
Line 118: Line 116:
  * [[faq#scripting_automation|FAQs about scripting]];   * [[faq#scripting_automation|FAQs about scripting]];
  * [[scripts|Useful example scripts]].   * [[scripts|Useful example scripts]].
 +

Last modified: by martin