Check a file exists on a website

Reply

Join Date: Jan 2009
Posts: 10
Reputation: No Pain No Gain is an unknown quantity at this point 
Solved Threads: 0
No Pain No Gain No Pain No Gain is offline Offline
Newbie Poster

Check a file exists on a website

 
0
  #1
Jan 12th, 2009
Currently my users download a database outside my app then from within it they can add the database to their main database. Now I want to have the app download and add the database all at once.

If I change the file extension to .txt the code below downloads the database as a text file but saves it as a mdb.

Dim strURL As String
Dim bData() As Byte ' Data variable
Dim intFile As Integer ' FreeFile variable

strURL = "http://www.asite/update1.txt"
intFile = FreeFile()
bData() = Inet1.OpenURL(strURL, icByteArray)
Open App.Path & "\update1.mdb" For Binary Access Write As #intFile
Put #intFile, , bData()
Close #intFile

But how can I check that the file exists on my site?

If the file doesn't exist, i.e. I haven't added the update to my site yet, the code still creates an update1.mdb that is really a text file that starts:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The page cannot be found</TITLE>
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Check a file exists on a website

 
0
  #2
Jan 12th, 2009
Note:Please use code tags when posting code. You can do this by typing [ code=vb ] (without spaces) put the code in, then end it with [ /code ] (also without spaces).
Attached Files
File Type: zip GetPage.zip (1.8 KB, 18 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 10
Reputation: No Pain No Gain is an unknown quantity at this point 
Solved Threads: 0
No Pain No Gain No Pain No Gain is offline Offline
Newbie Poster

Re: Check a file exists on a website

 
0
  #3
Jan 13th, 2009
Sorry about the code tags.

I've tried the code you attached and edited

Winsock1.RemoteHost = "codefaction.net" to the top level of my site

Send_HTTP_Header Winsock1, "/index.htm" to the path and file name (.txt) of a file I know isn't there

but the app insists the file is "found".

Is this because I am not looking for an HTML file? So when the .txt file is missing it is creates something like when trying to download an .mdb file?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Check a file exists on a website

 
0
  #4
Jan 13th, 2009
What the code does, (at least, what it's supposed to do) is use winsock to connect to the web server. Then it sends an HTTP request header to the server, requesting the page found in path "/index.htm", so if the page was http://www.somesite.com/thisthing/my.txt, then that part would be "/thisthing/my.txt". Then, what the web site does, it check for that file. If the file does not exist, the first line that it responds with, is a 404 (in the response header). So, the code checks for a 404 on the first line returned. What you could consider doing, is doing a msgbox on parts(0) right by the if instr(1, parts(0), "404") line (just above it), and see what it's actual line is.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 10
Reputation: No Pain No Gain is an unknown quantity at this point 
Solved Threads: 0
No Pain No Gain No Pain No Gain is offline Offline
Newbie Poster

Re: Check a file exists on a website

 
0
  #5
Jan 13th, 2009
I've tried writing it to a text box and I get

"HTTP/1.1 400 Bad Request"

Am I doing the remote host bit right? You put codefaction.net does it need anything in front of the site name? I get the same error whether I try a .html, .txt, a file that is there or a file that is missing.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 10
Reputation: No Pain No Gain is an unknown quantity at this point 
Solved Threads: 0
No Pain No Gain No Pain No Gain is offline Offline
Newbie Poster

Re: Check a file exists on a website

 
0
  #6
Jan 13th, 2009
I've tried variations of the remote host for my site and it never works, always a bad request. My website is probably on a shared server could that be the problem?

If I try your codefaction.net the request works.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC