Topic "Looking to SFTP download files based on dates written in filenames"

Author Message


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)
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24759
Location: Prague, Czechia
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)

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License