Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FtpFindFirstFile help!

Posted on 2002-04-13
7
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 70

Expert Comment

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

Expert Comment

by:Anthony Perkins
ID: 6938904
What is the problem you are having using this function?

Anthony
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 800 total points
ID: 6939570
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:blackpool1999
ID: 6939576
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
ID: 6939713
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
ID: 6939748
works great thanks
Blackpool
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6940518
Thanks for "A" grade!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

715 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