Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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

martin

Re: Looking to SFTP download files based on dates written in filenames

Well, this is not WinSCP, but VBA question.
Anyway, use & to concatenate strings in VBA, like:

Set transferResult = mySession.GetFiles("/reports/" & myvariable, "F:/SFTP/Downloads\", False, myTransferOptions)
Guest1111

Looking to SFTP download files based on dates written in filenames

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)