Using WinSCP .NET Assembly from WSH-hosted Active Scripting Languages
Advertisement
Installing and Registering for COM
First, you need to install the WinSCP .NET assembly and register it for COM.
Using from WSH
You use WinSCP .NET assembly from WSH as any other COM library.
Though there are some less known techniques that you may need to use, which are described in following sections.
Accessing Enumeration Values
As JScript and VBScript access COM classes via IDispatch, they do not make use of type library, hence they do not have direct access to constants defined there, like Protocol.Sftp for instance. To use these, you have to instruct WSH to import the type library into the script namespace.
You can use 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 JScript script embedded in WSF:
<job> <reference object="WinSCP.Session" /> <script language="JScript"> 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 xxxxxxxxxxx..."; var session = WScript.CreateObject("WinSCP.Session"); session.Open(sessionOptions); session.PutFiles("d:\\toupload\\*", "/home/user/"); </script> </job>
Advertisement
You run the .wsf file the same way as you run