Issue with VBSCRIPT
I'm trying to automate a connection with FTP site (SSL Explicit enc).
Here below my code
Option Explicit
' Setup session options
Dim sessionOptions, FtpSecure, TlsHostCertificateFingerprint, Explicit, Protocol_ftp
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_ftp
.FtpSecure = Explicit
.HostName = "xxxxxx"
.UserName = "xxxxxx"
.Password = "xxxxxx"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
session.SessionLogPath = "C:\TEMP\TestSessionLog.txt"
session.DebugLogPath = "C:\TEMP\TestDebugLog.txt"
' Connect
session.Open SessionOptions
Const ForReading = 1
Dim fileName, fileName2, remotePath, remotePath2, localPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\TEMP\RBC LBX NEXT SEQUENCE.ini", ForReading)
i = 0
Do Until objFile.AtEndOfStream
strNextLine = objFile.Readline
If strNextLine <> "" Then
'fileName = "LBXACN." & strNextLine
'fileName2 = "LBXACN." & strNextLine & ".downloaded%FTPS"
fileName = "pippo"
fileName = "pippo2"
End If
Loop
objFile.Close
'remotePath = "/outbound/HVHV" & fileName
'remotePath2 = "/outbound/HVHV" & fileName2
remotePath = fileName
remotePath2 = fileName2
localPath = "C:\INTERF\UCQ\RBC\LOCKBOX" & fileName
Dim fs
Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Dim download, remoteWriteTime, localWriteTime
If session.FileExists(remotePath) Then
' Download the file and throw on any error
session.GetFiles(remotePath, localPath).Check()
WScript.Echo "Download to C:\INTERF\UCQ\RBC\LOCKBOX\ done."
Else
WScript.Echo "File " & remotePath & " does not exist yet"
End If
If session.FileExists(remotePath2) Then
' Download the file and throw on any error
session.GetFiles(remotePath2, localPath).Check()
WScript.Echo "Download to C:\INTERF\UCQ\RBC\LOCKBOX\ done."
Else
WScript.Echo "File " & remotePath2 & " does not exist yet"
End If
' Disconnect, clean up
session.Dispose
The error is
Executing Assembly: WinSCPnet, Version=1.2.7.5235, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf; Path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WinSCPnet.DLL; Location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WinSCPnet.dll; Product: 5.7.1.0
Exception: System.ArgumentException: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.HostKey is not set.
in WinSCP.Session.SessionOptionsToOpenSwitches(SessionOptions sessionOptions)
in WinSCP.Session.SessionOptionsToOpenCommand(SessionOptions sessionOptions, String& command, String& log)
in WinSCP.Session.Open(SessionOptions sessionOptions)
Thanks in advance for your support.