-
FTP File Exists
Hello everyone
I have a function to check if a file on ftp server exists, here it is:
Code:
Public Function RemoteExists(strFile As String) As Boolean
Dim hSearch As Long
Dim FData As WIN32_FIND_DATA
If strFile = "" Then Exit Function
hSearch = FtpFindFirstFile(hConnection, strFile, FData, 0, 0) 'The hConnection is the handle of a ftp session (this code is a part of a class)
If hSearch <> 0 Then
InternetCloseHandle hSearch
RemoteExists = True
End If
End Function
It works, it check if there is a file or folder in the current FTP directory.
My problem is that when I call this function many times the computer slows down.
For example:
Code:
Dim x as Integer
For x=0 To 100
RemoteExists "abc" & x
Next x
After 20-40 calls, all the computer is very slow. When this loop finishes and I want to call others wininet functions like FtpGetCurrentDirectory they also slows down my computer. But when I shut down and open the FTP session again the function executes as fast as before.
Can you tell me what is happening???
-
I found a solution for my problem, I've remplaced that function:
Code:
Public Function RemoteExists(strFile As String) As Boolean
Dim hSearch As Long
Dim hNow As Long
Dim FData As WIN32_FIND_DATA
If strFile = "" Then Exit Function
hSearch = FtpFindFirstFile(hConnection, "*.*", FData, 0, 0) 'Get all the files
If hSearch <> 0 Then
RemoteExists = (MyTrim(FData.cFileName) = strFile) 'The function MyTrim removes the char 0 from a string
Do Until RemoteExists
hNow = InternetFindNextFile(hSearch, FData)
If hNow = 0 Then Exit Do
RemoteExists = (MyTrim(FData.cFileName) = strFile)
Loop
InternetCloseHandle hSearch
End If
End Function
Now I enumerate all the files from a dir and looking for the mine.
The strangest think is that this code is faster than the previous.
Any ideas why?
Last edited by chrispl; 06-24-2006 at 03:54 PM.
-
chrispl,how can we know why it is so fast unless & untill you supply us the codings behind the class you're using to execute your task.Will you be good enough to send an attachment of the codings?
-
I've just changed that function, it is faster and the rest of the code is the same.
If you want the code it's simple:
Function InternetOpen to open the internet, InternetConnect to connect to an ftp server, then you put a loop which execute the function RemoteExists (with the parameter you want) about 100 times. After this you use the InternetCloseHandle to close the handles of the connection.
When you use the first function (not modified) it is slower than when you use the new one.
In my case, I use the function RemoteExists to check if a file is on the server before uploading, so the user can cancel the upload if the file exists.
Similar Threads
-
By John Knoop in forum .NET
Replies: 8
Last Post: 02-28-2010, 01:57 PM
-
Replies: 146
Last Post: 08-12-2002, 10:40 PM
-
By Mort in forum VB Classic
Replies: 10
Last Post: 07-11-2001, 10:00 AM
-
Replies: 1
Last Post: 05-24-2001, 09:36 AM
-
By Paul in forum Database
Replies: 0
Last Post: 08-22-2000, 10:54 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks