CURLSMBS : how to check file exists

If I try to use CURLSMBS to download a remote file which does not exist, it bombs the app, even within a try…catch

Is there a way to check for the existence of a file on a web site before trying to download it?
(Doing an HTTPSocket.get will also download the file, which is large)

Hey Jeff. Here’s the content of a method with return type Boolean that I use for just such a purpose. I pass the URL to the method in a string. The method returns “true” if the file exists and “false” if not. Although I dimension a string variable for “DebugData”, I only use the resultant value of that for troubleshooting if needed. Hope it helps you.

[code] dim e as integer
dim d as new DownloadCURL

imgURL = ReplaceAll(imgURL, " ", “%20”) // NOTE: Spaces must be replaced with “%20” when using filenames having a URL

d.OptionNoBody=true
d.OptionURL=imgURL
d.CollectOutputData = true
d.SetOptionHTTPHeader array(“Cache-Control: no-cache”)
d.OptionVerbose = true
d.CollectDebugData = true

e=d.Perform

dim de as string = d.DebugData

if d.FileSize > 0 then // file exists
d.ClearData
return true
else // file does not exist
d.ClearData
return false
end if[/code]

Thanks.
I’ll add that now!

Jeff

Bombs the app? Please explain how that happens.
Maybe send me example project?

if the file doesn’t exist, it should give an error message.

The code I use is this: (using the sample DownloadCurl class from the MBS examples)

leadup is a string holding the full url up to but not including the file
eg http://www.mysite.com/mystuff/

updatepath is the end filename.
In my tests, the ‘incorrect’ filename was dw.pkg and the correct one was db.pkg
When update path was dw.pkg, the app terminated without an error.
When it is correctly db.pkg, the whole thing works

 [code] dest = specialfolder.Temporary.child(updatepath)
  b = BinaryStream.Create(dest, true) 
  d=new DownloadCURL
  msgbox leadup + updatepath
  d.OptionURL = leadup + updatepath
  
  e=d.Perform
  b.Close[/code]

I am sorry I can’t reproduce such a crash.
Can you send me a project which crashes for you?

I’ll try to extract that from the main code for you later in the week. Thanks for checking so far

Looks like i need a libCurl.dll file to make this work in Windows.
MBS site links to a dead page, and many of the pages about that being missing say ‘dont just download the dll as bad things may happen’

Any advice about where to get a 32 and a 64 bit version of this DLL file safely?
(Are there 2 distinct files?)

With CURLSMBS you don’t need DLL.

Only with CURLMBS (Without S).

I use these precompiled 32-bit binaries when I use libcurl. They should work with MBS, but I haven’t tested. These are linked from curl’s official download page even though they are provided by a third party. I haven’t tried the 64-bit binaries that are listed.

Thats what the docs said, but I was finding that it didnt work.
I think I have traced it to an out of date plugin.
The .cancel property is missing , the percent parameter is missing, and the finished event isnt there either.
Currently downloading a new set of plugins and will flush the cache before retrying.

Good idea. 15.4 is much better than 10 year old plugins.

The mess with the DLLs always has been that there are old copies, copies with dependencies, copies without SSL/SSH libraries inside and copies with non matching bit number.

So I prefer the internal library with the plugin.

For the benefit of anyone finding this thread in the future, if a file does not exist, something is still downloaded, and it has a size > 0
What comes down is the resultant ‘404’ page of html.

So the downloaded file size can be checked for ‘bigger than x bytes’, and perhaps read in as a string for checking.

I’ve got things working with the new plugin. (My existing one was 3 years old but had not been used until I added this code.)

GetInfoResponseCode gives 404 if file is not found.
200 indicates success.

Those response codes are only for HTTP.

for webservices, please check three times:

  1. result from Perform, to see if network was okay.
  2. ResponseCode to see if HTTP transport worked
  3. Error encoded in JSON/XML for error in web service.

[quote=233376:@Jeff Tullin]For the benefit of anyone finding this thread in the future, if a file does not exist, something is still downloaded, and it has a size > 0
What comes down is the resultant ‘404’ page of html.[/quote]
Not sure how to do this with MBS, but you can tell libcurl to treat status codes that are greater or equal to 400 as a failure (i.e. nothing downloaded).