Solved

FtpFindFirstFile help!

Posted on 2002-04-13
7
409 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

734 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