Page 1 of 2
Check file existence on Server
Posted: Sun Jan 20, 2013 5:27 pm
by alemrantareq
Hello everyone, i need to check a file exists or not on a server. I've tried several function & command but dont understand how to cook them properly. Can anyone teach me whats the exact command to check a server file existance?
The command will be - if the file exists, it will ask to download
I've found some examples in this forum; but all r ftp based, I mean to get a file I need to know username & pass. But I'm talking about downloading from a direct link. & the file is in rar format.
replies r most appreciated

Re: Check file existence on Server
Posted: Mon Jan 21, 2013 1:15 pm
by alemrantareq
Well, I've tried myself & built a script that helps me partially
Code: Select all
on mouseUp
put "http://siteurl.com/file.rar" into dFile
put specialfolderpath(0) & "/file.rar" into tFile
libURLDownloadToFile dFile, tFile
end mouseUp
But before it downloads the file, I need to check the file exists or not. Pls somebody help
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 1:32 pm
by Klaus
Mark already gave you the answer here:
http://forums.runrev.com/phpBB2/viewtop ... 320#p67359
"there is a file (or not) does only work with local files, so you need to ask the webserver if it can serve the file!
If NOT then an HTML 404 error is returned -> 404 = file not found -> Means "the result" is NOT empty in any case
after getting that URL. I am sure you have seen this in your browser at some time.
This is what I get after I enter a NON valid url in my browser:
------------------------------------------------------------------------------------------
Not Found
The requested URL /image.jpg was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at
http://www.major-k.de Port 80
........................................................................................
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 3:02 pm
by alemrantareq
Thanks Klaus. Yes I've seen such 404 error page many times in different websites. I've tested Mark's script & it works fine when there is such no 404 error handling in .htaccess file of that server. But now there are many sites using 404 handling scripts and redirect the visitors to the home page. In that case, Mark's script doesn't give the correct answer !!
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 3:12 pm
by Klaus
Ah, OK, well, good luck then

Re: Check file existence on Server
Posted: Mon Jan 21, 2013 3:38 pm
by alemrantareq
Klaus wrote:Ah, OK, well, good luck then

Bro, I've no luck if I can't get the correct answer.
Here is an example; suppose I need to check the existence of "file.rar" linking in "
http://thesiteurl.com/file.rar". Now I put the link into MyData. If MyData contains "file.rar" then it will download the file; else it will show the error dialog.
Can it be done through this way? I've tried -
Code: Select all
on mouseUp
put URL "http://thesiteurl.com/file.rar" into myData
put the result into rslt
if rslt contains "file.rar" then
// download will start
else
answer "No such file"
end if
end mouseUp
But it's not working

Re: Check file existence on Server
Posted: Mon Jan 21, 2013 3:46 pm
by Klaus
Please look up THE RESULT in the dictionary!
"THE RESULT" = EMPTY if an action had success!
Try this:
Code: Select all
on mouseUp
put URL "http://thesiteurl.com/file.rar" into myData
put the result into rslt
if rslt = EMPTY then
## SUCCESS!
## File is obviously on server!
## download will start
else
answer "There was an Error:" && rslt"
## This will cover ANY possible error like a connection error, timeout, server dow etc,
## and not only a NON existing file!
end if
end mouseUp
Best
Klaus
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 3:56 pm
by alemrantareq
bro, I've tried this -
Code: Select all
put URL "http://mysiteurl.com/file.rar" into myData
put the result into rslt
if rslt is empty then
answer "Found"
else
answer "Not Found"
end if
I've a file "file.rar" on my server. Then I've tried this script & says "Found". Then I modified the URL to "
http://mysiteurl.com/file.txt" & it also says "Found" where there is no such existence of "file.txt" on the server !!
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 4:21 pm
by Klaus
Hi, I am too old for this "bro" shit, so please just call me Klaus, thanks
Well, it always depends on how the webswerver is set up, although it should
NOT pretend to host a file that is not actually there.
But that is how THE RESULT works.
The server send something VALID (for RESULT), so the result is probably not the
best way to ensure the existence of the file.
I am afraid there is no special and "universal" recipe for your task, sorry.
At least I'm out of ideas...
Best
Klaus
Re: Check file existence on Server
Posted: Mon Jan 21, 2013 4:32 pm
by sturgis
Check both the result and the data itself. If its returning a custom 404, chances are it still has the 404 error string in there somewhere, so look look for it! Its also possible that the last headers that are sent back will reflect the url that was re-directed to for the custom 404. So you might look up headers in the dictionary and see if anything there is helpful.
Re: Check file existence on Server
Posted: Tue Jan 22, 2013 7:46 am
by shaosean
Not too certain if
libURLFollowHttpRedirects works on the put URL command, but give it a go..
Re: Check file existence on Server
Posted: Thu Jan 31, 2013 4:45 pm
by alemrantareq
checked with all the commands you've suggested, also custom 404 error checking; the file exists or not, in both case, it answers the same

Re: Check file existence on Server
Posted: Thu Jan 31, 2013 5:09 pm
by Klaus
Can you post (parts of) "the result" and "myData"?
Maybe this will give us a hint...
Re: Check file existence on Server
Posted: Thu Jan 31, 2013 10:15 pm
by Simon
Hi, I am too old for this "bro" shit, so please just call me Klaus,
You crack me up Klaus!!!
Simon
Re: Check file existence on Server
Posted: Fri Feb 01, 2013 4:48 pm
by alemrantareq
Klaus wrote:Can you post (parts of) "the result" and "myData"?
Maybe this will give us a hint...
Actually, I tried with making several scripts in different formats; but all are failed. Thats why I didnt save 'em
Now I forgot how did i cook them !!
