Differences
This shows you the differences between the selected revisions of the page.
2015-12-14 | 2015-12-14 | ||
Add JScript example (109.81.210.121) | jscript: intro, anchor, consistent syntax, comments, enumerations, event prefix, semicolons (martin) | ||
Line 325: | Line 325: | ||
</code> | </code> | ||
- | ==== [[JScript]] JScript example === | + | ==== [[jscript]] JScript (WSH) Example ==== |
+ | In this example the JScript script is embedded into WSF file, to allow [[library_com_wsh#enums|access to enumeration values]]. | ||
<code javascript> | <code javascript> | ||
<job> | <job> | ||
Line 331: | Line 333: | ||
<script language="JScript"> | <script language="JScript"> | ||
- | function SessionEvent_FileTransferred(sender, e) | + | // Session.FileTransferred event handler |
+ | |||
+ | function session_FileTransferred(sender, e) | ||
{ | { | ||
if (e.Error == null) | if (e.Error == null) | ||
{ | { | ||
- | WScript.Echo("Upload of "+e.FileName+" succeeded"); | + | WScript.Echo("Upload of "·+·e.FileName·+·" succeeded"); |
} | } | ||
else | else | ||
Line 346: | Line 350: | ||
if (e.Chmod.Error == null) | if (e.Chmod.Error == null) | ||
{ | { | ||
- | WScript.Echo("Permisions of "+e.Chmod.FileName+" set to " + e.Chmod.FilePermissions); | + | WScript.Echo("Permisions of "·+·e.Chmod.FileName·+·" set to " + e.Chmod.FilePermissions); |
} | } | ||
else | else | ||
{ | { | ||
- | WScript.Echo("Setting permissions of "+e.Chmod.FileName+" failed: " + e.Chmod.Error); | + | WScript.Echo("Setting permissions of "·+·e.Chmod.FileName·+·" failed: " + e.Chmod.Error); |
} | } | ||
} | } | ||
else | else | ||
{ | { | ||
- | WScript.Echo("Permissions of "+e.Destination+" kept with their defaults"); | + | WScript.Echo("Permissions of "·+·e.Destination·+·" kept with their defaults"); |
} | } | ||
Line 362: | Line 366: | ||
if (e.Touch.Error == null) | if (e.Touch.Error == null) | ||
{ | { | ||
- | WScript.Echo("Timestamp of "+e.Touch.FileName+" set to " + e.Touch.LastWriteTime); | + | WScript.Echo("Timestamp of "·+·e.Touch.FileName·+·" set to " + e.Touch.LastWriteTime); |
} | } | ||
else | else | ||
{ | { | ||
- | WScript.Echo("Setting timestamp of "+e.Touch.FileName+" failed: " + e.Touch.Error); | + | WScript.Echo("Setting timestamp of "·+·e.Touch.FileName·+·" failed: " + e.Touch.Error); |
} | } | ||
} | } | ||
Line 375: | Line 379: | ||
} | } | ||
} | } | ||
+ | |||
+ | // Main script | ||
try | try | ||
Line 380: | Line 386: | ||
// Setup session options | // Setup session options | ||
var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions"); | var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions"); | ||
- | sessionOptions.Protocol = 0;//Protocol_Sftp; | + | sessionOptions.Protocol = Protocol_Sftp; |
sessionOptions.HostName = "example.com"; | sessionOptions.HostName = "example.com"; | ||
sessionOptions.UserName = "user"; | sessionOptions.UserName = "user"; | ||
Line 386: | Line 392: | ||
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"; | sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"; | ||
- | var session = WScript.CreateObject("WinSCP.Session", "SessionEvent_"); | + | var session = WScript.CreateObject("WinSCP.Session", "session_"); |
try | try | ||
Line 395: | Line 401: | ||
// Synchronize files | // Synchronize files | ||
var synchronizationResult = session.SynchronizeDirectories( | var synchronizationResult = session.SynchronizeDirectories( | ||
- | 0 /* Local */, "C:\\work\\files", "/home/user/files", false) | + | SynchronizationMode_Remote, "D:\\www", "/home/martin/public_html", false); |
// Throw on any error | // Throw on any error | ||
- | synchronizationResult.Check() | + | synchronizationResult.Check(); |
} | } | ||
finally | finally | ||
Line 414: | Line 420: | ||
</job> | </job> | ||
</code> | </code> | ||
+ | |||
==== Real-Life Example ==== | ==== Real-Life Example ==== | ||