Differences

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

2008-02-14 2008-02-14
typo (martin) Modifying the script automatically (martin)
Line 25: Line 25:
===== Notes ===== ===== Notes =====
When connecting to particular host for the first time, you will be prompted to [[ssh#verifying_the_host_key|verify host key]]. When connecting to particular host for the first time, you will be prompted to [[ssh#verifying_the_host_key|verify host key]].
 +
 +===== Modifying the script automatically =====
 +You may want to modify the script automatically. For example you may want to operate it with different file each time. To do that you need to generate new script file each time. To automate that, make a wrapper script file. For simple tasks you can use build-in Windows scripting functionality from batch file (''.bat''). For complex tasks, you will need to use some scripting language, such as PHP or Perl.
 +
 +Following example shows batch file that takes filename on command line and generates WinSCP script file to upload that file to remote server:
 +
 +<code>
 +rem Generate temporary script to upload %1
 +echo option batch on > script.tmp
 +echo option confirm off >> script.tmp
 +echo open session >> script.tmp
 +echo put %1 >> script.tmp
 +echo exit >> script.tmp
 +
 +rem Execute script
 +winscp /script=script.tmp
 +
 +rem Delete temporary script
 +del script.tmp
 +</code>
 +
 +Now you can run the batch file like (supposing you have saved it to file ''upload.bat''):
 +
 +<code>
 +upload.bat c:\myfile.txt
 +</code>
 +
 +You can also put the script on your desktop and than easily use it by dropping files on its icon. Windows automatically run the script and passes path to dropped file as command-line parameter.
 +