Using WinSCP Assemblies in VBScript

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
fazleskhan
Newbie
Posts: 5
Joined: Tue Apr 05, 2016 7:52 pm

Using WinSCP Assemblies in VBScript

Post by fazleskhan » Wed Oct 12, 2016 3:55 pm

I am trying to use the WinSCP assemblies inside a VBScript routine nested in Macroscheduler. The script needs to transfer files to a sftp server

I am following the directions here to register the COM
https://winscp.net/eng/docs/library_install#registering

and this bit of code to connect to the target sftp server
https://winscp.net/eng/docs/library_com_wsh#vbscript

If the dll is not registered I get the error 424 'Object required', which makes sense

If the dll is registered I get the error 430 'Class doesn't support Automation' when trying to create the WinSCP.SessionOptions object. Any suggestions what I am doing wrong?

Sample vbscript code

Code: Select all

Dim sessionOptions
Set sessionOptions = CreateObject("WinSCP.SessionOptions")
With sessionOptions
    .Protocol = "Protocol_Sftp"
    .HostName = "mysftp.com"
    .UserName = "username"
    .Password = "password"
    .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With

User avatar
Marcus Tettmar
Site Admin
Posts: 7084
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Using WinSCP Assemblies in VBScript

Post by Marcus Tettmar » Fri Oct 14, 2016 10:16 am

I'm not sure we can help you here. This is a Macro Scheduler forum and your question appears to be about Microsoft VBScript and a third party component (WinSCP).

But obvious generic stuff ... have you registered the component? Is it the 32 bit version? Have you registered it with the 32 bit regsvr?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fazleskhan
Newbie
Posts: 5
Joined: Tue Apr 05, 2016 7:52 pm

Re: Using WinSCP Assemblies in VBScript

Post by fazleskhan » Thu Nov 03, 2016 8:48 pm

From what I could tell the 32bit version was registered. Anyway I opted to call winscp via Shell.Exec here is the code snip in case anyone else is interested

Code: Select all

      Dim objShell, strCmd, objExec
      Set objShell = CreateObject("WScript.Shell")

        strCmd = Chr(34) & "c:\Program Files (x86)\WinSCP\WinSCP.com" & Chr(34) & Chr(32) & _
            "/command" & Chr(32) & _
            Chr(34) & "echo uploading file" & Chr(34) & Chr(32) & _
            Chr(34) & "open" & Chr(32) & "sftp://<username>:<password>@sftp.mytest.com/" & _
                Chr(32) & "-hostkey=" & Chr(34) & Chr(34) & "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" & Chr(34) & Chr(34) & _
                Chr(32) & "-rawsettings" & Chr(32) & "FSProtocol=2" & Chr(34) & Chr(32) & _
            Chr(34) & "lcd" & Chr(32) & ".\" & Chr(34) & Chr(32) & _
            Chr(34) & "cd" & Chr(32) & ".\" & Chr(34) & Chr(32) & _
            Chr(34) & "put" & Chr(32) & "myfile.txt" & Chr(34) & Chr(32) & _
            Chr(34) & "exit" & Chr(34)

        Set objExec = objShell.Exec(strCmd)
        Dim line
        Do
            line = objExec.StdOut.ReadLine
             WScript.Echo "winscp line " & line
        Loop While Not objExec.StdOut.atEndOfStream

Post Reply