Error code 80131500 and message "Connection failed"

Advertisement

adrianlai
Joined:
Posts:
1
Location:
Desperate looking for solutions

Error code 80131500 and message "Connection failed"

Hi, I am having trouble to connect to remote ftps server with .wsf scripts. But I can connect with WinSCP program and WS_FTP program. The error message is "connection failed" and the error code is 80131500. Here is code I am using:
<job>
<reference object="WinSCP.Session"/>
<script language="VBScript">

Option Explicit

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_ftp
.ftpSecure = FtpSecure_Implicit
.PortNumber = 62000
.HostName = "xxxxx.xx.xxx"
.UserName = "xxxxxx"
.Password = "xxxxxxx"

End With

Dim session
Set session = WScript.CreateObject("WinSCP.Session")

' Connect
session.Open sessionOptions

Dim today, stamp, logdate
logdate = Now & VbCrLf
today = Date
stamp = Year(today)
If Month(today) < 10 Then
stamp = stamp & "0"
End If
stamp = stamp & Month(today)
if Day(today) - 1 < 10 Then
stamp = stamp & "0"
End If
stamp = stamp & Day(today)

Dim fileName, remotePath, localPath
fileName = stamp & "_DATA.csv"
remotePath = "/xxx/xx_xxx_" & fileName
localPath = "x:\xx\xxx\xxx\xxxxD_" & fileName

Dim fs, sftplog
Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set sftplog = fs.OpenTextFile("E:\xxx\xxx.log", 8, True) '1 = reading, 2 = writing new, 8 = appending


Dim download, remoteWriteTime, localWriteTime

If session.FileExists(remotePath) Then
If Not fs.FileExists(localPath) Then
sftplog.WriteLine logdate & " File " & remotePath & " exists, local backup " & localPath & " does not"
download = True
Else
remoteWriteTime = CDate(session.GetFileInfo(remotePath).LastWriteTime)
localWriteTime = fs.GetFile(localPath).DateLastModified

If remoteWriteTime > localWriteTime Then
sftplog.WriteLine _
logdate & " File " & remotePath & " as well as local backup " & localPath & " exist, " & _
"but remote file is newer (" & remoteWriteTime & ") than local backup (" & localWriteTime & ")"
download = True
Else
sftplog.WriteLine _
logdate & " File " & remotePath & " as well as local backup " & localPath & " already existed. "
sftplog.WriteLine " Remote file created on " & remoteWriteTime
sftplog.WriteLine " Local backup " & localWriteTime
download = False
End If
End If

If download Then
' Download the file and throw on any error
session.GetFiles(remotePath, localPath).Check()

sftplog.WriteLine logdate & " Download to backup done."
End If
Else
sftplog.WriteLine logdate & " File " & remotePath & " does not exist yet"
End If
sftplog.Close
' Disconnect, clean up
session.Dispose

</script>
</job>

Kindly help me to solve this problem.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: Error code 80131500 and message "Connection failed"

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum