Differences
This shows you the differences between the selected revisions of the page.
| 2014-06-12 | 2014-07-17 | ||
| using Add-Type cmdlet instead of Assembly.LoadFrom method (martin) | jscript and vbscript examples (martin) | ||
| Line 162: | Line 162: | ||
| </code> | </code> | ||
| + | |||
| + | ==== [[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> | ||
| + | <job> | ||
| + | <reference object="WinSCP.Session"/> | ||
| + | <script language="JScript"> | ||
| + | |||
| + | try | ||
| + | { | ||
| + | // Setup session options | ||
| + | var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions"); | ||
| + | sessionOptions.Protocol = Protocol_Sftp; | ||
| + | sessionOptions.HostName = "example.com"; | ||
| + | sessionOptions.UserName = "user"; | ||
| + | sessionOptions.Password = "mypassword"; | ||
| + | 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"); | ||
| + | |||
| + | try | ||
| + | { | ||
| + | // Connect | ||
| + | session.Open(sessionOptions); | ||
| + | |||
| + | var directoryInfo = session.ListDirectory("/home/martin/public_html") | ||
| + | |||
| + | for (var enumerator = new Enumerator(directoryInfo.Files); !enumerator.atEnd(); enumerator.moveNext()) | ||
| + | { | ||
| + | var fileInfo = enumerator.item(); | ||
| + | WScript.Echo( | ||
| + | fileInfo.Name + " with size " + fileInfo.Length + | ||
| + | ", permissions " + fileInfo.FilePermissions + | ||
| + | " and last modification at " + fileInfo.LastWriteTime); | ||
| + | } | ||
| + | } | ||
| + | finally | ||
| + | { | ||
| + | // Disconnect, clean up | ||
| + | session.Dispose(); | ||
| + | } | ||
| + | } | ||
| + | catch (e) | ||
| + | { | ||
| + | WScript.Echo("Error: " + e.message); | ||
| + | WScript.Quit(1); | ||
| + | } | ||
| + | |||
| + | </script> | ||
| + | </job> | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ==== [[vbscript]] VBScript (WSH) Example ==== | ||
| + | In this example the VBScript script is embedded into WSF file, to allow [[library_com_wsh#enums|access to enumeration values]]. | ||
| + | |||
| + | <code vb> | ||
| + | <job> | ||
| + | <reference object="WinSCP.Session"/> | ||
| + | <script language="VBScript"> | ||
| + | |||
| + | Option Explicit | ||
| + | |||
| + | ' Setup session options | ||
| + | Dim sessionOptions | ||
| + | Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions") | ||
| + | With sessionOptions | ||
| + | .Protocol = Protocol_Sftp | ||
| + | .HostName = "example.com" | ||
| + | .UserName = "user" | ||
| + | .Password = "mypassword" | ||
| + | .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
| + | End With | ||
| + | |||
| + | Dim session | ||
| + | Set session = WScript.CreateObject("WinSCP.Session") | ||
| + | |||
| + | ' Connect | ||
| + | session.Open sessionOptions | ||
| + | |||
| + | Dim directoryInfo | ||
| + | Set directoryInfo = session.ListDirectory("/home/martin/public_html") | ||
| + | |||
| + | Dim fileInfo | ||
| + | For Each fileInfo In directoryInfo.Files | ||
| + | WScript.Echo fileInfo.Name & " with size " & fileInfo.Length & _ | ||
| + | ", permissions " & fileInfo.FilePermissions & _ | ||
| + | " and last modification at " & fileInfo.LastWriteTime | ||
| + | Next | ||
| + | |||
| + | ' Disconnect, clean up | ||
| + | session.Dispose | ||
| + | |||
| + | </script> | ||
| + | </job> | ||
| + | </code> | ||
| ==== Real-Life Example ==== | ==== Real-Life Example ==== | ||