Solved

FtpFindFirstFile help!

Posted on 2002-04-13
7
384 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
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 200 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

914 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

13 Experts available now in Live!

Get 1:1 Help Now