Dim fileName as string
Dim uploadFolder as string
filename = “c:\temp\*” ‘ files to be loaded from this folder. wilcards can be used
uploadFolder = “/upload/” ‘ Default folder where files will be loaded
Try
Dim sessionOptions as new WinSCP.SessionOptions
with sessionOptions
.Protocol = WinSCP.Protocol.Sftp
.HostName = GBL_SFTP_HOST_NAME
.UserName = GBL_SFTP_USERNAME
.SshPrivateKeyPath = GBL_SFTP_PRIVATEKEY_PATH
.PortNumber = GBL_SFTP_PORT
.SshHostKeyFingerprint = GBL_SFTP_HOST_SSH_KEY
end with
using session as new WinSCP.Session
session.Open(sessionOptions)
Dim transferOptions as new WinSCP.TransferOptions
transferOptions.FilePermissions = $Null
transferOptions.PreserveTimestamp = $False
Dim transferResult as WinSCP.TransferOperationResult
transferResult = session.PutFiles(Filename, uploadFolder, false, transferOptions)
transferResult.Check() ‘THrows the first error if not successful
For Each transfer as WinSCP.TransferEventArgs in transferResult.Transfers
‘Write results to Event Viewer or SQL table or Log Table
‘This will display a message box with the results
MessageBox.Show(“Upload of file “ & transfer.FileName & ” successful.”)
Next
end using
Catch ex as System.Exception
MessageBox.Show(ex.ToString()) ‘Display any Exceptions
Finally
End Try
return true