Solved

FtpFindFirstFile help!

Posted on 2002-04-13
7
391 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 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 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

825 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