Topic "Issue with VBSCRIPT"

Author Message
Gianluca_Italy

Guest


Good Morning.
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Do you have your script wrapped into WFS?
If not, the symbol Protocol_ftp won't resolve correctly.
See https://winscp.net/eng/docs/library_com_wsh
Guest




Good Morning,
yes but i've the same error.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Please attach a full session and debug log files showing the problem (using the latest version of WinSCP).

Set Session.SessionLogPath and Session.DebugLogPath. If you do not want to post the logs publicly, you can mark the attachments as private.

Also attach your complete WSF file.
_________________
Martin Prikryl
Guest




In attachment
TestDebugLog.txt (13.59 KB) Private file

Description: (none)

TEST_FTP.txt (1.68 KB) Private file

Description: WSF file

Guest




Good Evening,
sorry to bother you.

Do you have some new about my issue ?

Thanks in advance
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Only now I noticed that you declare these variables:
Dim ..., FtpSecure, TlsHostCertificateFingerprint, Explicit, Protocol_ftp

They obviously shadow the constants/symbols from WinSCP .NET assembly. You have to remove that declaration.
Guest




Many Thanks !!!
It works.

Can I ask you another information about session.MoveFile ?
Is it possibile to move files from remote path to another remote path (for example from /temp to /test) ? Both paths are on the same FTP site.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
See Session.MoveFile:
https://winscp.net/eng/docs/library_session_movefile
Guest




Good evening.
I'm not able to use wsf because i've this error :


Version of C:\INTERF\jobs\Scripts\winscp\winscp.exe is 5.1.6.3394, product WinSCP version is 5.1.6.0
[2015-05-06 22:11:46.299Z] [0001] Exception: WinSCP.SessionLocalException: The version of C:\INTERF\jobs\Scripts\winscp\winscp.exe (5.1.6.0) does not match version of this assembly C:\INTERF\jobs\Scripts\winscp\WinSCPnet.DLL (5.7.1.0). You can disable this check using Session.DisableVersionCheck (not recommended).

I tried with

session.DisableVersionCheck = true

without success :-(
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Anonymous wrote:
Good evening.
I'm not able to use wsf because i've this error :


Version of C:\INTERF\jobs\Scripts\winscp\winscp.exe is 5.1.6.3394, product WinSCP version is 5.1.6.0
[2015-05-06 22:11:46.299Z] [0001] Exception: WinSCP.SessionLocalException: The version of C:\INTERF\jobs\Scripts\winscp\winscp.exe (5.1.6.0) does not match version of this assembly C:\INTERF\jobs\Scripts\winscp\WinSCPnet.DLL (5.7.1.0). You can disable this check using Session.DisableVersionCheck (not recommended).

So why don't you get same version of both files?
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