FTP File Exists


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: FTP File Exists

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45

    Exclamation 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???

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45

    Lightbulb

    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.

  3. #3
    Join Date
    Dec 2005
    Posts
    92
    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?

  4. #4
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    45
    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

  1. Check if file exists
    By John Knoop in forum .NET
    Replies: 8
    Last Post: 02-28-2010, 01:57 PM
  2. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  3. FTP and Windows file time date stamp
    By Mort in forum VB Classic
    Replies: 10
    Last Post: 07-11-2001, 10:00 AM
  4. Replies: 1
    Last Post: 05-24-2001, 09:36 AM
  5. 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center