Connection has been unexpectedly closed. Server sent command exit status 0
"mySession.Open mySessionOptions"
connection has been unexpectedly closed. Server sent command exit status 0.Authentication failed
Please Help.
Option Explicit
Sub Connect_To_SFTP()
Dim mySession As New session
' Enable custom error handling
On Error Resume Next
Upload mySession
' Query for errors
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description
' Clear the error
Err.Clear
End If
' Disconnect, clean up
mySession.Dispose
' Restore default error handling
On Error GoTo 0
End Sub
Sub Upload(ByRef mySession As session)
Dim works As String
' Setup session options
Dim mySessionOptions As New sessionOptions
'bool GiveUpSecurityAndAcceptAnySshHostKey
With mySessionOptions
.Protocol = Protocol_Sftp
.HostName = "lab.com"
.UserName = "*****"
.Password = "******"
.GiveUpSecurityAndAcceptAnySshHostKey = True
End With
' Connect
mySession.Open mySessionOptions
' Upload files
Dim transferOptions As New transferOptions
'Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
transferOptions.TransferMode = TransferMode_Binary
Dim transferResult
Set transferResult = mySession.GetFiles("/Result/Output_TXT/*", "c:\toupload\", False, transferOptions)
' Throw on any error
transferResult.Check
' Print results
Dim transfer
For Each transfer In transferResult.Transfers
Debug.Print "Download of " & transfer.Filename & " succeeded"
Next
' Disconnect, clean up
mySession.Dispose
End Sub