Having an FTP code issue

R

Rico

Hi All,

I have an FTP routine in my A2K2 database that I am using to transfer files.
When I call the FtpFindFirstFile API, I get an error 12002 which is a
timeout error. I've removed the timeout from the FTP server, but I still
get this error. I read that the files can can only be enumerated once using
this function and if it's called again, it will produce an error. I think
this is what is happening, since when I close the database and re-open it, I
can run this function for the first time without issue.

My question is, how do I tell if the files / folders have been enumerated
once already and how can I reset this so I can enumerate again? This is the
function that is giving me problems;

Public Sub GetFileNames(Optional pRemoteDir, Optional pFileSpec)
'Fill the FileNames collection with list
'of files matching pFileSpec from server's
'current directory

Dim hFind As Long
Dim LastErr As Long
Dim fdata As WIN32_FIND_DATA
'
'Bail out if server connection not established
If m_hCon = 0 Then RaiseError errNotConnected
'
'Handle optional parameters
If Not IsMissing(pRemoteDir) Then m_RemoteDir = pRemoteDir
If Not IsMissing(pFileSpec) Then m_FileSpec = pFileSpec
'
'Handle empty properties
If Len(m_RemoteDir) = 0 Then m_RemoteDir = "."
If Len(m_FileSpec) = 0 Then m_FileSpec = "*.*"
'

ClearFileNames

'Change directory on server
Me.SetDir m_RemoteDir
'
'Find first file matching FileSpec
fdata.cFileName = String(MAX_PATH, 0)
'Obtain search handle if successful
'FtpSetCurrentDirectory m_hCon, "."

hFind = FtpFindFirstFile(m_hCon, m_FileSpec, fdata, 0, 0)
LastErr = Err.LastDllError
If hFind = 0 Then
'Bail out if reported error isn't end-of-file-list
If LastErr <> ERROR_NO_MORE_FILES Then
RaiseError errFindFirst
End If
'Must be no more files
Exit Sub
End If
'
'Reset variable for next call
LastErr = NO_ERROR
'
'Add filename to the collection
FileNames.Add Left(fdata.cFileName, _
InStr(1, fdata.cFileName, vbNullChar, vbBinaryCompare) - 1)
Do
'Find next file matching FileSpec
fdata.cFileName = String(MAX_PATH, 0)
If InternetFindNextFile(hFind, fdata) = False Then
LastErr = Err.LastDllError
If LastErr = ERROR_NO_MORE_FILES Then
'Bail out if no more files
Exit Do
Else
'Must be a 'real' error
InternetCloseHandle hFind
RaiseError errFindNext
End If
Else
'Add filename to the collection
FileNames.Add Left(fdata.cFileName, _
InStr(1, fdata.cFileName, vbNullChar, vbBinaryCompare) - 1)
End If
Loop
'
'Release the search handle
InternetCloseHandle hFind

End Sub

Thanks!
Rick
 
C

Clif McIrvin

Rico - sounds like you're making a reasonable presumed diagnosis ...
Have you looked for forums targeted to using APIs? I have extremely
limited experience working with APIs; I do recall having had some
success using advanced google searching of microsoft.com for
documentation of API calls in the past.

Happy Hunting!
 
R

Rico

Thanks for the response Clif. I thought I had exhausted my Google
searching, but will give it a nother try.

Rick
 
C

Clif McIrvin

Rico said:
Thanks for the response Clif. I thought I had exhausted my Google
searching, but will give it a nother try.

Rick


You're welcome!
I hate it when one of my posts just languishes with no response. I know
there are users of API calls in these precincts .... perhaps if your
additional searching dead-ends you could try re-posting under a
different subject line focusing on help for API functions ....

Seems like the API info I found was in the "programmers reference"
materials on MSDN or TechNet, as I recall.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top