Solved

FtpFindFirstFile help!

Posted on 2002-04-13
7
380 Views
Last Modified: 2008-02-01
I am writing an FTP server component and I am having some trouble with the FtpFindFirstFile Function.
I am able to connect to the server and run other functions like put and delete.  Here is the function declaration and call.

Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Public Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String '* MAX_PATH
    cAlternate As String '* 14
End Type

Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Dim pData As WIN32_FIND_DATA
pData.cFileName = String(260, 0)
   
lngHINet = FtpFindFirstFile(lngINetConn, "*.*", pData, 0, 0)

any ideas?
Blackpool
0
Comment
Question by:blackpool1999
7 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
see this free component (complete with source code): http://www.freevbcode.com/ShowCode.Asp?ID=1593
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
What is the problem you are having using this function?

Anthony
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
Comment Utility
Well, what i use to enumerate files at ftp site is:
'NOTE: You need api declarations in general declarations section of the form that has this routine.

Public Function EnumFilesFTP(ByRef lcount As Long, Optional ByVal sExtension As String = "*.*", Optional
lview As Control) As String()

Dim arrFiles() As String, idx As Long
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
Dim FTime As FILETIME
Dim STime As SYSTEMTIME
Dim lstItem  As Object
'create a buffer
pData.cFileName = String(MAX_PATH, 0)
   
'find the first file
hFind = FtpFindFirstFile(m_InetConnect, sExtension, pData, 0, 0)
   
Do While hFind <> 0
   
   'show the filename
   Dim FName As String
   FName = StripNull(pData.cFileName)
   If FName <> "." And FName <> ".." Then
      idx = idx + 1
      ReDim arrFiles(idx)
      arrFiles(idx) = FName
      If Not lview Is Nothing Then
          Set lstItem = lview.ListItems.Add(, , FName)
          With lstItem.ListSubItems
           .Add , , pData.nFileSizeLow
           FileTimeToSystemTime pData.ftCreationTime, STime
           .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
           FileTimeToSystemTime pData.ftLastWriteTime, STime
           .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
           FileTimeToSystemTime pData.ftLastAccessTime, STime
           .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
          End With
      End If
      'find the next file
      lRet = InternetFindNextFile(hFind, pData)
      'if there's no next file, exit do
      If lRet = 0 Then Exit Do
      'show the filename
   End If
Loop
   
'close the search handle
InternetCloseHandle hFind
'returns names of files found and quantity
lcount = idx
EnumFilesFTP = arrFiles
End Function

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:blackpool1999
Comment Utility
I seem to be using the same parameters in the FtpFindFirstFile as you are:
 
a valid connection handle
"*.*"
pData.cFileName = String(260, 0)
0
0

Could there be a problem with either "*.*" or pData.cFileName = String(260, 0)?

When I use these parameters the handle allways returns 0

I know the connection handle is valid because my putFile function works fine.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Just copy the code and try it. I use it seven days a week every 10 minutes with no problem!
0
 

Author Comment

by:blackpool1999
Comment Utility
works great thanks
Blackpool
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thanks for "A" grade!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now