Could not create WinSCP.SessionOptions

Advertisement

silviab2
Guest

Could not create WinSCP.SessionOptions

Hi,
I have a vbscript that given the remote path, the local path, a start date and a end date, downloads all the file in the remote path updated between the two dates. Running it on a server with OS Windows Server 2008 R 2 Datacenter, it works perfectly, but when I run it on another server with OS Windows Server 2012 R2 Standard, I got the following error:
WScript.CreateObject: Could not create object named "WinSCP.SessionOptions"

Also a pop up windows opens that says:
The following feature couldn't be installed:
.NET Framework 3.5 (includes .NET 2.0 and 3.0)

However, on this server there is already .NET Framework 4.5, so why it seems that it needs version 3.5? Also, in the old server there is only version 4 and there are no problems there.
Do I have to use different commands with version 4.5 of .NET? Or is it mandatory to download the older version?
Below there's the code of the script.
Thanks
Silvia
<job>
<reference object="WinSCP.Session"/>
<script language="VBScript">
Option Explicit
' Check and read input arguments
Dim numArgs
numArgs = WScript.Arguments.Count
If numArgs < 2 Then
  WScript.Echo "Usage: /DINI:<Now> /DFIN:<Now> /R_PATH:<remote-path> /L_PATH:<local-path>"
  WScript.Quit ( 1 )
End If

Dim valArgs
Set valArgs = WScript.Arguments.Named
If Not ( valArgs.Exists( "R_PATH" ) ) And Not ( valArgs.Exists( "L_PATH" ) ) Then
  WScript.Echo "Usage: /DINI:<Now> /DFIN:<Now> /R_PATH:<remote-path> /L_PATH:<local-path>"
  WScript.Quit ( 2 )
End If

Dim vRemotePath, vLocalePath,vHost,vUser,vPsw
vRemotePath = valArgs.Item( "R_PATH" )
vLocalePath = valArgs.Item( "L_PATH" )
vHost=valArgs.Item( "Host" )
vUser=valArgs.Item( "User" )
vPsw=valArgs.Item( "Psw" )

Dim oFSO
Set oFSO = CreateObject( "Scripting.FileSystemObject" )
If Not oFSO.FolderExists( vLocalePath ) Then
    set oFSO = Nothing
    WScript.Echo "L_PATH does not exists!!!"
    WScript.Quit ( 3 )
End If
set oFSO = Nothing

Dim vDINI, vDFIN
If valArgs.Exists( "DINI" ) Then
  vDINI = cDate(valArgs.Item( "DINI" ))
  If Not isDate(vDINI)  Then
    WScript.Echo "DINI non è una data!!!"
    WScript.Quit ( 4 )
  End If
End If
If valArgs.Exists( "DFIN" ) Then
  vDFIN =cDate(valArgs.Item( "DFIN" ))
  If Not isDate(vDFIN)  Then
    WScript.Echo "DFIN non è una data!!!"
    WScript.Quit ( 5 )
  End If
End If
If Not valArgs.Exists("Host") Then
   WScript.Echo "Manca l'host"
    WScript.Quit ( 6 )
End If
If Not valArgs.Exists("User") Then
   WScript.Echo "Manca l'user"
    WScript.Quit ( 7 )
End If
If Not valArgs.Exists("Psw") Then
   WScript.Echo "Manca la password"
    WScript.Quit ( 8 )
End If
Set valArgs = Nothing
' Setup session options

Dim sessionOpts
Set sessionOpts = WScript.CreateObject( "WinSCP.SessionOptions" )
With sessionOpts
    .Protocol = Protocol_Ftp
    .HostName = vHost
    .UserName = vUser
    .Password = vPsw
End With

Dim session
Set session = WScript.CreateObject( "WinSCP.Session" )
' Connect
session.Open sessionOpts
Set sessionOpts = Nothing

Dim dirInfo
Set dirInfo = session.ListDirectory( vRemotePath )
Dim remoteFile, localeFile, fileInfo
For Each fileInfo In dirInfo.Files
  If fileInfo.LastWriteTime >= vDINI and fileInfo.LastWriteTime <= vDFIN Then
    remoteFile = vRemotePath + fileInfo.Name
    localeFile = vLocalePath + fileInfo.Name
    session.GetFiles( remoteFile, localeFile ).Check( )
    WScript.Echo remoteFile
  End If
Next
Set dirInfo = Nothing
'Disconnect and clean up
session.Dispose
Set session = Nothing
WScript.Quit( 0 )
</script>
</job>

Reply with quote

Advertisement

aput
Joined:
Posts:
9
Location:
EUR

I see this thread was never finalized, so for what it is worth:
I get that same Windows prompt (to install .NET 3.5) on my clean WIN10 install, the first time I want to use the .NET assembly.

Andre

Reply with quote

Sylvie
Guest

Re: Could not create WinSCP.SessionOptions

aput wrote:

I see this thread was never finalized, so for what it is worth:
I get that same Windows prompt (to install .NET 3.5) on my clean WIN10 install, the first time I want to use the .NET assembly.

Andre

Hi Andre,

I faced the same issue on a Windows 2016 server having .net Framework 4.6 installed but no .Net Framework 3.5
Activating .Net Framework 3.5 solved my issue!
Tkx for the tip!

Sylvie

Reply with quote

aput
Joined:
Posts:
9
Location:
EUR

Hi Martin,
Here is a 3rd report of a user that is pretty sure WinSCP triggers a .NET 3.5 install.
And on another OS (WIN10, Windows Server 2008R2, Windows Server 2016).
Do you have any clue?
It is not a bug, I just find it strange.
Andre

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum