Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

usa

Thanks, it works also in scripting version of Visual Basic now.
martin

Re: Fail in VBScript, VBA (untyped), work in VBA (typed), VB.NET

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 https://winscp.net/tracker/1136
usa

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

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:
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:
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:
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:
Invalid procedure call or argument

at the following statement:
session.Open sessionOptions


This VBA code also fails (when removing BOTH the declarations, the error message is the same):
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:
Object doesn't support this property or method

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


VBScript code ALWAYS fails:
<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:
Module1.wsf(19, 10) Microsoft VBScript runtime error: Object doesn't support this property or method: 'SynchronizeDirectories'
:twisted: :twisted: :twisted: