Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

ruyguy30

Object Required Error during FTP Transfer

Help! When the FTP part of my script runs. I am getting Error: Object Required
This is not full code, the rest of it works, but this is the code for just the FTP.

' Setup session options
Set objSFTPSessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
 
'Determine what MODE we're in and modify username accordingly
If UCase(MODE) = "PROD" Then
   'We're in production
   AmendLog "Production mode detected. Logging in accordingly"
   strSFTPUsername = SFTP_PROD_USERNAME
Else
   AmendLog "Test mode detected. Logging in accordingly"
   strSFTPUsername = SFTP_TEST_USERNAME
End If
 
With objSFTPSessionOptions
    .PortNumber = 2224
    .Protocol = 0
    .HostName = SFTP_HOST_NAME
    .UserName = strSFTPUsername
    '.Password = ""
    .SshPrivateKeyPath = SFTP_AUTHENTICATION_KEY
    .PrivateKeyPassphrase = SFTP_KEY_PASSPHRASE
    .SshHostKeyFingerprint = SSH_HOST_KEY
End With
 
On Error Resume Next
Set objSFTPSession = WScript.CreateObject("WinSCP.Session")
 
' Connect
objSFTPSession.Open objSFTPSessionOptions
 
If Err.Number <> 0 Then
   AmendLog "Error opening SFTP session: " & Err.Description
   processFile = False
   Exit Function
End If
 
' Upload files
Set objSFTPTransferOptions = WScript.CreateObject("WinSCP.TransferOptions")
objSFTPTransferOptions.TransferMode = TransferMode_Binary
 
Set objSFTPTransferResults = objSFTPSession.PutFiles(strDestinationPath, SFTP_SUBFOLDER, False, objSFTPTransferOptions)
 
' Throw on any error
objSFTPTransferResults.Check
 
' Print results
For Each objSFTPTransferResult In objSFTPtransferResults.Transfers
   If objSFTPTransferResult.Error = Null Then
      AmendLog "Upload of " & objSFTPTransferResult.FileName & " succeeded"
      bolTransferSuccess = True
 
      'Move file to processed folder
      AmendLog "Moving processed file to Submitted folder"
      objFSO.MoveFile strDestinationPath, PROCESSED_FILE_DIRECTORY & "\" & strDestinationFileName
   Else
      AmendLog "Upload of " & objSFTPTransferResult.FileName & " failed with error " & objSFTPTransferResult.Error.Message
      bolTransferSuccess = False
   End If
Next
 
' Disconnect, clean up
objSFTPSession.Dispose
 
'Clean up
Set objRecord = Nothing
Set objConn = Nothing
Set objSourceFile = Nothing
Set objFSO = Nothing
 
'Check for presence of failed transfer of one or more files
If bolTransferSuccess = True Then
   processFile = True
Else
   processFile = False
End If
 
End Function