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>

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?

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.

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.

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.

This article has been dead for over six months. Start a new discussion instead.