943,719 Members | Top Members by Rank

Ad:
Jan 12th, 2009
0

Check a file exists on a website

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
No Pain No Gain is offline Offline
10 posts
since Jan 2009
Jan 12th, 2009
0

Re: Check a file exists on a website

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, 193 views)
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 13th, 2009
0

Re: Check a file exists on a website

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
No Pain No Gain is offline Offline
10 posts
since Jan 2009
Jan 13th, 2009
0

Re: Check a file exists on a website

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 13th, 2009
0

Re: Check a file exists on a website

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
No Pain No Gain is offline Offline
10 posts
since Jan 2009
Jan 13th, 2009
0

Re: Check a file exists on a website

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
No Pain No Gain is offline Offline
10 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help! Print the Text in a Textbox and / or Label to Printer
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: showing report groupwise in a data report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC