Connecting to a remote file on my site

Hello,

I have a question that may sound pretty basic but since I’ve never done anything like this I don’t know where to start let me explain.

I need an App (Mac) that I’m developing for a specific client to do when opening a check if a file exists (.txt) in a folder on their site and if it doesn’t exist returns with a message.

It would go to www.sitexxx.com/ files/ ACT.txt and if the file does not exist the program returns an error message in a Msgbox.

What version of xojo are you using?

Xojo 2017 Release 2.1

Sorry for delay, had to afk. Have a look in Example Projects>Communication>Internet>HTTPDownloader

In the Download method, think about changing the Downloader.Get to

Downloader.Get(URL As String, Timeout As Integer) As String

Check the in built Language Reference for more info.

Let us know if you get stuck :slight_smile:

[quote=462442:@]Sorry for delay, had to afk. Have a look in Example Projects>Communication>Internet>HTTPDownloader

In the Download method, think about changing the Downloader.Get to

Downloader.Get(URL As String, Timeout As Integer) As String

Check the in built Language Reference for more info.

Let us know if you get stuck :)[/quote]

Thanks for the help I’ll have a look in this.

I think this is not yet what I need, I need to check if the file is there to continue or get a warning Not Found for APP not to continue.

Any ideas are welcome !

Here you go Paulo, it might need some tweaking depending on the server set up/language etc.

https://www.dropbox.com/s/7m0z7fmcex5f8mh/DoesPageExistPaulo.xojo_binary_project?dl=0

HTTPSecureSocket.Get(URL As String, Timeout As Integer) As String
should be what you need ?

[quote=462462:@]Here you go Paulo, it might need some tweaking depending on the server set up/language etc.

https://www.dropbox.com/s/7m0z7fmcex5f8mh/DoesPageExistPaulo.xojo_binary_project?dl=0[/quote]

Again thanks so much and Jean-Yves Pochez for the help you are giving me !

Julian I don’t know what may be happening, but when I change the project path to my site (or any other fiction) and do the test it always returns True.

To be clear, I just opened the project that kindly sent me and changed the address (Path) and return true every time, I don’t know what could be going wrong, any idea why this is happening?

If your server doesn’t include the string “404 - File Or directory Not found.” in the source when the file is not found then it won’t match correctly, you’ll need to tweak that as I mentioned above. If your server does any redirection or uses https then the code will also need to be tweaked. PM me the full URL if you want and I’ll take a quick look.

Yeah, there are all these variables that can make it difficult if I need to target more than 1 server or even replace it, I think I’ll have to think better about it because I imagined a simple system to recognize whether a page exist and return me a true or false but I will have to think better.

Maybe I’ll even have to study a bit of how access via database this, anyway thanks for the immense help you gave me!

I use this, but it relies on knowing what the file content should be, rather than whether a page ‘exists at all’
On my site I have an XML file sitting
This checks whether it exists and is XML

[code] dim h as new HTTPSocket
h.yield = true
dim x as string
x= h.get (“http://www,mysite.com/afolder/thefile.xml”,2)

if h.HTTPStatusCode = 200 then // got an OK response… now is it our file or a redirect?
if left(x,5) = “<?xml” then

msgbox “File exists”
end if
end if[/code]

[quote=462504:@Jeff Tullin]I use this, but it relies on knowing what the file content should be, rather than whether a page ‘exists at all’
On my site I have an XML file sitting
This checks whether it exists and is XML

[code] dim h as new HTTPSocket
h.yield = true
dim x as string
x= h.get (“http://www,mysite.com/afolder/thefile.xml”,2)

if h.HTTPStatusCode = 200 then // got an OK response… now is it our file or a redirect?
if left(x,5) = “<?xml” then

msgbox “File exists”
end if
end if[/code][/quote]

Oh, I like your approach, I’ll test it and tell you again if it works for what I need.

Thanks in advance for the help, Jeff Tullin !

The way I do it (for the records) is the other way around. It works fine, though I’m not sure if there are drawbacks in this design.

On the server, I put this php file:

<?php $filepath="./MyFile"; if(!file_exists($filepath)){ echo "0"; }else{ echo "1"; } ?>

In the Xojo code, I use a HTTPSocket and connect to the php file:
HS1.Get(app.RegURL) 'e.g. in the open event

In the HTTPSocket’s PageReceived, the “content” variable is “0” or “1”, what the php script wrote.

Once this works, you can pass parameters to, for example, test for other files, if you want to reuse the php script for more than one file:
HS1.Get(app.RegURL+"?filename="+File.Name)
(don’t forget to grab the parameter in the php file; also, encrypting the passed name is a good idea, so eventual hackers won’t be able to use your script to test for random file existences).

[quote=463225:@Arnaud Nicolet]The way I do it (for the records) is the other way around. It works fine, though I’m not sure if there are drawbacks in this design.

On the server, I put this php file:

<?php $filepath="./MyFile"; if(!file_exists($filepath)){ echo "0"; }else{ echo "1"; } ?>

In the Xojo code, I use a HTTPSocket and connect to the php file:
HS1.Get(app.RegURL) 'e.g. in the open event

In the HTTPSocket’s PageReceived, the “content” variable is “0” or “1”, what the php script wrote.

Once this works, you can pass parameters to, for example, test for other files, if you want to reuse the php script for more than one file:
HS1.Get(app.RegURL+"?filename="+File.Name)
(don’t forget to grab the parameter in the php file; also, encrypting the passed name is a good idea, so eventual hackers won’t be able to use your script to test for random file existences).[/quote]

Thanks Arnaud Nicolet for your suggestion, i will try this too.

I have this project stopped in recent days, but will be back soon.