Hi everyone
I am using vba to download files into a folder then open in excel. I have no other coding knowledge, so I cannot move to powershell, C#, etc.
I want to be able to download SFTP files based on file names. The last 6 or 8 digits in the file represent date, either MMDDYYYY or MMYYYY.
I have code written out to identify all of these and parse the text in the file name to get the date, I just dont know the syntax of the WinSCP codes to be able to extract files from the folder based on user inputs only.
This is the code I've got from when we used FTP:
NamePart = Split(FileNameArray(1), "_")
Parts = Split(NamePart(1), ".")
Set CurrReport = New Report
If Len(Parts(0)) = 8 Then
CurrReport.Month = Mid(Parts(0), 1, 2)
CurrReport.Day = Mid(Parts(0), 3, 2)
CurrReport.Year = Mid(Parts(0), 5, 4)
ElseIf Len(Parts(0)) = 6 Then
CurrReport.Month = Mid(Parts(0), 1, 2)
CurrReport.Year = Mid(Parts(0), 3, 4)
End If
How can I apply this to my SFTP code and modify it to only download the files I want based on variable string name?
Currently, my SFTP code does this and downloads ALL files from reports:
Dim transferResult As TransferOperationResult
Set transferResult = mySession.GetFiles("/reports/*", "F:/SFTP/Downloads\", False, myTransferOptions)