Differences
This shows you the differences between the selected revisions of the page.
2012-02-10 | 2012-02-17 | ||
library_install (martin) | vbscript example (martin) | ||
Line 15: | Line 15: | ||
You can use [[wp>Windows_Script_File|Windows Script File]] (WSF) and its ''<reference>'' tag for that. It makes WSH import all //enums// from the assembly type library into constants in script namespace with name like ''<type>_<member>'', e.g. ''Protocol.Sftp'' becomes ''Protocol_Sftp''. | You can use [[wp>Windows_Script_File|Windows Script File]] (WSF) and its ''<reference>'' tag for that. It makes WSH import all //enums// from the assembly type library into constants in script namespace with name like ''<type>_<member>'', e.g. ''Protocol.Sftp'' becomes ''Protocol_Sftp''. | ||
- | See how ''%%<reference object="WinSCP.Session"/>%%'' allows use of ''Protocol_Sftp'' in below script: | + | See how ''%%<reference object="WinSCP.Session"/>%%'' allows use of ''Protocol_Sftp'' in below JScript script embedded in WSF: |
<code javascript> | <code javascript> | ||
<job> | <job> | ||
- | <reference object="WinSCP.Session"/> | + | <reference object="WinSCP.Session"·/> |
<script language="JScript"> | <script language="JScript"> | ||
Line 57: | Line 57: | ||
function session_FileTransferred(sender, e) | function session_FileTransferred(sender, e) | ||
{ | { | ||
- | WScript.Echo(e.FileName + "·=>·" + e.Destination); | + | WScript.Echo(e.FileName, "=>", e.Destination); |
} | } | ||
var session = WScript.CreateObject("WinSCP.Session", "session_"); | var session = WScript.CreateObject("WinSCP.Session", "session_"); | ||
+ | </code> | ||
+ | |||
+ | And equivalent in VBScript: | ||
+ | |||
+ | <code vb> | ||
+ | Sub session_FileTransferred(sender, e) | ||
+ | WScript.Echo e.FileName, "=>", e.Destination | ||
+ | End Sub | ||
+ | |||
+ | Set session = WScript.CreateObject("WinSCP.Session", "session_") | ||
</code> | </code> | ||
Line 68: | Line 78: | ||
<code javascript> | <code javascript> | ||
<job> | <job> | ||
- | <reference object="WinSCP.Session"/> | + | <reference object="WinSCP.Session"·/> |
<script language="JScript"> | <script language="JScript"> | ||
Line 99: | Line 109: | ||
WScript.Echo("Upload of", enumerator.item().FileName, "succeeded"); | WScript.Echo("Upload of", enumerator.item().FileName, "succeeded"); | ||
} | } | ||
+ | |||
+ | </script> | ||
+ | </job> | ||
+ | </code> | ||
+ | |||
+ | ===== VBScript Example ===== | ||
+ | This example is functionally equivalent to [[library#example|overall C# example for WinSCP .NET assembly]]. | ||
+ | |||
+ | <code vb> | ||
+ | <job> | ||
+ | <reference object="WinSCP.Session" /> | ||
+ | <script language="VBScript"> | ||
+ | |||
+ | ' Setup session options | ||
+ | Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions") | ||
+ | |||
+ | sessionOptions.Protocol = Protocol_Sftp | ||
+ | sessionOptions.HostName = "example.com" | ||
+ | sessionOptions.UserName = "user" | ||
+ | sessionOptions.Password = "mypassword" | ||
+ | sessionOptions.SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
+ | |||
+ | Set session = WScript.CreateObject("WinSCP.Session") | ||
+ | |||
+ | ' Connect | ||
+ | session.Open(sessionOptions) | ||
+ | |||
+ | ' Upload files | ||
+ | Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions") | ||
+ | transferOptions.TransferMode = TransferMode_Binary | ||
+ | |||
+ | Set transferResult = session.PutFiles("d:\\toupload\\*", "/home/user/", False, transferOptions) | ||
+ | |||
+ | ' Throw on any error | ||
+ | transferResult.Check() | ||
+ | |||
+ | ' Print results | ||
+ | For Each transfer in transferResult.Transfers | ||
+ | WScript.Echo "Upload of", transfer.FileName, "succeeded" | ||
+ | Next | ||
</script> | </script> | ||
</job> | </job> | ||
</code> | </code> |