Topic "Fail in VBScript, VBA (untyped), work in VBA (typed), VB.NET"

Author Message
usa
[View user's profile]

Joined: 2013-09-11
Posts: 8
Some methods of the COM objects fail in VBScript and VBA (with untyped variables), but work in VBA (with typed variables) and VB.NET.

What's wrong? I need to make it work in VBScript.

The VB.NET code works perfectly:
Code:
Imports System
Imports WinSCP

Module Module1
    Sub Main()
        Dim sessionOptions As SessionOptions
        Dim session As Session

        sessionOptions = CreateObject("WinSCP.SessionOptions")
        sessionOptions.Protocol = Protocol.Ftp
        sessionOptions.FtpSecure = FtpSecure.Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        session = CreateObject("WinSCP.Session")
        session.Open(sessionOptions)
        session.SynchronizeDirectories(SynchronizationMode.Local, "***", "***", False)
    End Sub
End Module


This VBA code also works perfectly:
Code:
Option Explicit

Sub Main()
        Dim sessionOptions As sessionOptions
        Dim session As session

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub


This VBA code fails:
Code:
Option Explicit

Sub Main()
        Dim sessionOptions ' <-- !!! Removed type declaration
        Dim session As session

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub

It says:
Code:
Invalid procedure call or argument

at the following statement:
Code:
session.Open sessionOptions


This VBA code also fails (when removing BOTH the declarations, the error message is the same):
Code:
Option Explicit

Sub Main()
        Dim sessionOptions As sessionOptions
        Dim session ' <-- !!! Removed type declaration

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub

It says:
Code:
Object doesn't support this property or method

at the following statement:
Code:
session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False


VBScript code ALWAYS fails:
Code:
<job>
   <reference object="WinSCP.Session" />
   <script language="VBScript">

   Option Explicit

        Dim sessionOptions
        Dim session

        Set sessionOptions = CreateObject("WinSCP.SessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
 
   </script>
</job>

It says:
Code:
Module1.wsf(19, 10) Microsoft VBScript runtime error: Object doesn't support this property or method: 'SynchronizeDirectories'
Twisted Evil Twisted Evil Twisted Evil
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Not sure about the typed/untyped issue. I'm not a VB/VBA expert.
But the problem with SynchronizeDirectories is fixed already in the latest beta/RC version.
See http://winscp.net/tracker/show_bug.cgi?id=1136
usa
[View user's profile]

Joined: 2013-09-11
Posts: 8
Thanks, it works also in scripting version of Visual Basic now.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License