FTP retrieving a file using Visual Basic FTPGetFile and wildcards

I am writing a VB6 module that retrieves a file from an FTP server using the FtpGetFile command.  Is there a way to use wildcards with the FtpGetFile command when trying to retrieve a file?  For example, the file on the ftp server is "myfile_2008-11-06.dat".  I want to retrieve the file using a wildcard in the filename expression like "myfile*.dat".   The FtpGetFile command doesn't appear to like or recognize the "*" as a wildcard.
VBStudentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nathan RileyFounderCommented:
Not exactly sure how as someone had created it before me.  But it has something to do with a global variable.  
localInvoiceFile = "C:\Clients\Strat\File Uploads\Customer Uploads\ProMed\Working\" + Trim(DTSGlobalVariables("RemoteInvoiceFileName").Value)

Open in new window

0
nffvrxqgrcfqvvcCommented:
You won't be able to get that API to do that without some help. What you can do is use FtpFindFirstFile , FtpFindNextFile and then setup your own wildcard function.
0
nffvrxqgrcfqvvcCommented:
Correction:

FtpFindFirstFile,InternetFindNextFile
0
nffvrxqgrcfqvvcCommented:
The following should help you. Only uses a simple Like operation for the wildcard matching but you get the idea.
Option Explicit
 
Private Type WIN32_FIND_DATA_W
    dwFileAttributes            As Long
    ftCreationTime              As Currency
    ftLastAccessTime            As Currency
    ftLastWriteTime             As Currency
    nFileSizeHigh               As Long
    nFileSizeLow                As Long
    dwReserved0                 As Long
    dwReserved1                 As Long
    cFileName(520)              As Byte
    cAlternateFileName(28)      As Byte
End Type
 
Private Declare Function InternetOpenA Lib "wininet.dll" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnectA Lib "wininet.dll" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Long, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lcontext As Long) As Long
Private Declare Function FtpFindFirstFileW Lib "wininet.dll" (ByVal hConnect As Long, ByVal lpszSearchFile As Long, ByVal lpFindFileData As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetFindNextFileW Lib "wininet.dll" (ByVal hConnect As Long, ByVal lpvFindData As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long
Private Declare Sub RtlZeroMemory Lib "kernel32" (ByRef dst As Any, ByVal nBytes As Long)
 
Private Function ToString(ByVal szData As String) As String
    ToString = Left$(szData, InStr(1, szData, vbNullChar) - 1)
End Function
 
Public Sub EnumFtpDirectory( _
    ByVal szHost As String, _
    ByVal dwPort As Long, _
    ByVal szUser As String, _
    ByVal szPass As String, _
    ByVal szDirectory As String, _
    Optional ByVal szWildCard As String = vbNullString)
    
    '   Call EnumFtpDirectory("ftp.site.com", 21, "username", "password", "/directory", "wildcard*")
    
    Dim hOpen       As Long
    Dim hConn       As Long
    Dim hFind       As Long
    Dim w32         As WIN32_FIND_DATA_W
    
    Dim szFileName  As String
    
    RtlZeroMemory w32, Len(w32)
    hOpen = InternetOpenA("FTP", 1, vbNullString, vbNullString, 1)
    hConn = InternetConnectA(hOpen, szHost, dwPort, szUser, szPass, 1, 0, 2)
    hFind = FtpFindFirstFileW(hConn, StrPtr(szDirectory), VarPtr(w32), 0, 0)
    
    Do
        szFileName = ToString(w32.cFileName)
        
        If LenB(szWildCard) = 0 Then
            ' * return all results. (ftpgetfile)...
            Debug.Print szFileName
        Else
            If szFileName Like szWildCard Then
            ' * return only wildcard results (ftpgetfile)...
                Debug.Print szFileName
            End If
        End If
        
    Loop Until InternetFindNextFileW(hFind, VarPtr(w32)) = 0
 
    InternetCloseHandle hConn
    InternetCloseHandle hOpen
    InternetCloseHandle hFind
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBStudentAuthor Commented:
Thank you.....there is always more than one way to skin a cat.  I never thought of that way...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.