I think I'm almost there. Can you check the code? Is there that stands out as a potential problem?
' ...
' ...
On Error Resume Next
' Connect
Set session = WScript.CreateObject("WinSCP.Session")
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
sessionOptions.Protocol = Protocol_SFTP
sessionOptions.HostName = "this.xx.gov"
sessionOptions.UserName = "username"
sessionOptions.Password = "xxxxxxx"
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2....."
If Err.number > 0 Then
Transfer_Succeeded_b = False
ErrorNumber = Err.number
ErrorDescription = Err.Description
ErrorSource = Err.Source
Err.Clear
Call LogError( "Problem Assigning Session settings " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
End If
session.Open sessionOptions
If Err.number = 0 Then
' Upload files
Set transferOptions = GetTransferOptions()
Set transferResult = session.PutFiles( File_From_s, DESTINATIONFOLDER, False, transferOptions )
' Throw on any error
transferResult.Check
If Err.number > 0 Then
Transfer_Succeeded_b = False
ErrorNumber = Err.number
ErrorDescription = Err.Description
ErrorSource = Err.Source
Err.Clear
Call LogError( "Problem Transferring " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
Call SendErrorMessage( "Problem Transferring " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
End If
' Returns false
Result_x = transferResult.IsSuccess()
' Returns the name of the file that attempted to send, even though it didn't succeed.
For Each transfer In transferResult.Transfers
Dim FileName_s
FileName_s = transfer.FileName
LogStatus( "Upload of " & transfer.FileName & " succeeded" )
Next
Else
Transfer_Succeeded_b = False
ErrorNumber = Err.number
ErrorDescription = Err.Description
ErrorSource = Err.Source
Err.Clear
Call LogError( "Problem Opening Session for " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
Call SendErrorMessage( "Problem Opening Session for " & File_From_s & " to " & DESTINATIONFOLDER, ErrorNumber, ErrorDescription, ErrorSource )
End If
' Disconnect, clean up
session.Dispose
' ...
' ...
' Earlier in the script, this function is defined
' No errors, and confirmed that the CONSTANTs are defined'
Function GetTransferOptions
Dim TransferOptions_obj
Set TransferOptions_obj = WScript.CreateObject( "WinSCP.TransferOptions" )
TransferOptions_obj.TransferMode = TransferMode_Ascii
TransferOptions_obj.OverwriteMode = OverwriteMode_Overwrite
Result_x = TransferMode_Ascii
Result_x = OverwriteMode_Overwrite
Result_x = TransferOptions_obj.TransferMode
Result_x = TransferOptions_obj.OverwriteMode
If Err.number > 0 Then
Transfer_Succeeded_b = False
ErrorNumber = Err.number
ErrorDescription = Err.Description
ErrorSource = Err.Source
Err.Clear
End If
Set GetTransferOptions = TransferOptions_obj
End Function