Connecting to a remote file on my site

  1. 7 months ago

    Paulo V

    8 Nov 2019 Porto Alegre, Brasil

    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.

  2. Julian S

    8 Nov 2019 Xojo Pro UK

    What version of xojo are you using?

  3. Paulo V

    8 Nov 2019 Porto Alegre, Brasil

    Xojo 2017 Release 2.1

  4. Julian S

    8 Nov 2019 Xojo Pro UK

    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 :)

  5. Paulo V

    8 Nov 2019 Porto Alegre, Brasil

    @Julian S 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 :)

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

  6. Paulo V

    8 Nov 2019 Porto Alegre, Brasil
    Edited 7 months ago

    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 !

  7. Julian S

    8 Nov 2019 Xojo Pro UK

    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

  8. Jean-Yves P

    8 Nov 2019 Testers, Xojo Pro Europe (France, Besançon)
    Edited 7 months ago
    HTTPSecureSocket.Get(URL As String, Timeout As Integer) As String

    should be what you need ?

  9. Paulo V

    8 Nov 2019 Porto Alegre, Brasil
    Edited 7 months ago

    @Julian S 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

    Again thanks so much Julian Samphire 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?

  10. Julian S

    8 Nov 2019 Xojo Pro UK

    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.

  11. Paulo V

    8 Nov 2019 Porto Alegre, Brasil
    Edited 7 months ago

    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!

  12. Jeff T

    8 Nov 2019 Midlands of England, Europe

    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

     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
  13. Paulo V

    8 Nov 2019 Porto Alegre, Brasil

    @Jeff T 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

    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

    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 !

  14. 6 months ago

    Arnaud N

    15 Nov 2019 Testers, Xojo Pro A lost country in Switzerland.

    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).

  15. Paulo V

    15 Nov 2019 Porto Alegre, Brasil
    Edited 6 months ago

    @Arnaud N 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).

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

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

or Sign Up to reply!