Announcement

Collapse
No announcement yet.

URLDownLoadToFile

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • URLDownLoadToFile

    hi everyone,

    i've tried the example here to download a url to file whice works fine.
    http://www.powerbasic.com/support/pb...ad.php?t=29338

    however i was trying to run a pbcc exe script on our windows 2003 server to do the same thing. no error code was returned and no file is created.

    Code:
    %inet_e_invalid_url = - 2146697214& 'url string is not valid
    %inet_e_no_session = - 2146697213& 'no session found.
    %inet_e_cannot_connect = - 2146697212& 'unable to connect to server.
    %inet_e_resource_not_found = - 2146697211& 'requested resource is not found.
    %inet_e_object_not_found = - 2146697210& 'requested object is not found.
    %inet_e_data_not_available = - 2146697209& 'requested data is not available.
    %inet_e_download_failure = - 2146697208& 'failure occurred during download.
    %inet_e_authentication_required = - 2146697207& 'requested navigation requires authentication.
    %inet_e_no_valid_media = - 2146697206& 'required media not available or valid.
    %inet_e_connection_timeout = - 2146697205& 'connection timed out.
    %inet_e_invalid_request = - 2146697204& 'request is invalid.
    %inet_e_unknown_protocol = - 2146697203& 'protocol is not recognized.
    %inet_e_security_problem = - 2146697202& 'navigation request has encountered a security issue.
    %inet_e_cannot_load_data = - 2146697201& 'unable to load data from the server.
    %inet_e_cannot_instantiate_object = - 2146697200& 'unable to create an instance of the object.
    %inet_e_redirect_failed = - 2146697196& 'attempt to redirect the navigation failed.
    %inet_e_redirect_to_dir = - 2146697195& 'navigation redirected to a directory.
    %inet_e_cannot_lock_request = - 2146697194& 'unable to lock request with the server.
    %inet_e_use_extend_binding = - 2146697193& 'reissue request with extended binding.
    %inet_e_terminated_bind = - 2146697192& 'binding is terminated.
    %inet_e_code_download_declined = - 2146697960& 'permission to download is declined.
    %inet_e_result_dispatched = - 2146696704& 'result is dispatched.
    %inet_e_cannot_replace_sfp_file = - 2146696448& 'cannot replace a protected system file protection (sfp) file.
    
    
    #debug error on
    #compile exe
    $include "win32api.inc"
    
    declare function getmodulefilename lib "kernel32.dll" alias "getmodulefilenamea" ( byval hmodule as dword, lpfilename as asciiz, byval nsize as dword ) as dword
    
    function pbmain as long
      '
      dim surl as asciiz * 2048
      dim localfile as asciiz * 100
      dim tl1 as long
      '
      stdout "content-type: text/html"
      stdout $crlf
      '
      localfile = "test.htm"
      surl = "http://www.powerbasic.com
      tl1= urldownloadtofile( byval 0&, surl, localfile, byval 0&, byval 0& )
      stdout "return code " + str$(tl1)
      '
    end function
    ------------------

  • #2
    Hi Steve,

    Make sure the username that your IIS web runs as has permissions to write to the folder you're writing too. You may want to verify the actual path that you're writing to as well. I don't think that the exe will write to the same folder it resides on, unless you specifically state the path. Maybe your test.htm file got written somewhere else on the HD, maybe the folder where the IIS process runs from.

    Scott


    ------------------
    Scott Wolfington
    http://www.boogietools.com
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

    Comment


    • #3
      Thanks Scott for the quick response.

      I have tested the folder permsiions and the script can write to the folder is resides in.

      After calling the web page I did a search of the entire hard disc and the file was not found.

      ------------------

      Comment


      • #4
        Can you set your sURL variable to a web page on your local web server, and then check the web logs to see if your PB EXE is reaching the page?

        Scott


        ------------------
        Scott Wolfington
        http://www.boogietools.com
        Scott Wolfington
        [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

        Comment


        • #5
          Same result, no error and no file.

          ------------------

          Comment


          • #6
            Did your web server create a log entry for the request your exe made to sURL? In other words, I'm wondering if your EXE is even reaching the server of the URL you're trying to hit.

            {edit: You may have to enable logging on your IIS web.}

            ------------------
            Scott Wolfington
            http://www.boogietools.com



            [This message has been edited by Scott Wolfington (edited March 09, 2005).]
            Scott Wolfington
            [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

            Comment


            • #7
              Steve

              Are you running the script using the standard system account, perhaps from an AT job?

              If so, the script may not have permissions to access the network. What you see is that the script works fine when run from an interactive, logged in user, but fails when run from the Scheduler. Is that what you are seeing?

              Cheers

              -- Jim

              Comment


              • #8
                Hi Jim,

                I think he's running his EXE as a CGI via a web server, and starting the script by pointing his web browser to it.

                Scott


                ------------------
                Scott Wolfington
                http://www.boogietools.com
                Scott Wolfington
                [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

                Comment


                • #9
                  Jim,

                  I am accessing the script via the web browser.

                  Interesting,

                  I can run the script from the local machine by clicking the file in my computer etc and I can access any URL (Internal or internet).

                  If I run the script by accessing it via IE (local or any machine on the local lan) then I can only access pages on the local machine and nothing via the internet.

                  The server box can access the internet though.

                  I also tried to use Lances WebGet but this fails with error 24 Device time-out - (%ERR_DEVICETIMEOUT)

                  ------------------

                  Here is the log entry for the visit

                  2005-03-10 07:46:20 GET /cgi-bin/test.cgi - 81.153.160.206 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1) - 200 145


                  [This message has been edited by Steve Bouffe (edited March 10, 2005).]

                  Comment


                  • #10
                    Hi Steve,

                    Sorry, I have more questions than answers. I'm not sure of the solution, so I'm just trying to narrow things down for you. When you're running the exe from the local machine by double clicking it, which user are you logged in as? It's probably a different user than the user that your IIS web is running as. When calling your exe through IE, via the web server, your exe will run within the context of the web user you configured for that web. Hmm, it may even run within the user context that you have the World Wide Web Publishing service running as too. Which OS are you running? If it's XP, could the new built-in firewall stuff be blocking certain users from accessing the Internet? Any other software based firewall issues on that machine? When your exe successfully called your test.cgi script, and created the log entry, was that done when calling the script through IE? When that log entry occurred, did the LocalFile Test.htm file get created too?

                    Hopefully something here is helpful.

                    Scott

                    ------------------
                    Scott Wolfington
                    http://www.boogietools.com

                    [This message has been edited by Scott Wolfington (edited March 10, 2005).]
                    Scott Wolfington
                    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

                    Comment


                    • #11
                      I'm logged on locally (via remote desktop) to the server as administrator.

                      We are using Windows 2003 Server Standard Edition.

                      No firewall on the system.

                      Yes the log entry was created when calling the script via IE but the local file was not created.

                      I hope this can be solved!

                      ------------------

                      Comment


                      • #12
                        It seems the user your web is running as doesn't have permissions to make remote Internet requests. It doesn't sound like a localmachine network issue, as you can reach the local webserver from your exe, yet the call to URLDOWNLOADTOFILE won't write out the file when successfully connecting to a local web resource. I don't know much about Windows 2003, but maybe there is some policy stuff that you can look at for your IIS web user. We know your web user has permissions to write the file system, based on one of your posts. You said the URLDOWNLOADTOFILE isn't erroring out, but it doesn't look like there is any error trapping available with that function (strange), but maybe I'm missing it. Ok, one last thing I can think of to try. Change the user that your IIS Web is running as to the user that you're currently logged into the server via term services as. This would only be a quick temporary test, you definitely don't want your IIS web running as Administrator (as you already know). See if the exe runs within that context via the web server.

                        Sorry I can't be of more help.

                        Scott

                        ------------------
                        Scott Wolfington
                        http://www.boogietools.com

                        [This message has been edited by Scott Wolfington (edited March 10, 2005).]
                        Scott Wolfington
                        [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

                        Comment


                        • #13
                          I added my IIS account to the administrator group and this had no effect, just got the same response so I've changed it back!

                          At the moment I'm running a bridge program. The script dumps a file in a directory and the bridge program executes the request and places the result in another folder where the script then reads the file.

                          This seems to work ok but as the site traffic increases it will propably not do.

                          Any help to cure this would be great!

                          here is the url www.ukfindandbuy.com


                          ------------------

                          Comment


                          • #14
                            Summary of effects

                            if you use your browser on the lan and access the exe then you can pass a local web page and all works fine and file is created but you can't pass an internet site address
                            Q. in the log, when you do this does is map your account? with IE it may be sending credentials to the server to say you are an administrator, if this is so your login name will appear in the log, does it?

                            If you use your script from the internet then nothing works.
                            Q: if you forget about writing the text to a file can you just bounce it back to the user to see if you go it? ie, is the file write all that's failing or is the text get failing too?
                            Q: usually cgi directories only have execute permissions on them for obvious reasons, this would mean that you can't write to that directory, if you have another directory with all access allowed can you write to there?

                            Q: If you split this up into componant CGI jobs:
                            -1 a cgi app that does nothing but disply text
                            -2 a cgi app that gets text from a web server and does nothing (put a sniffer on the server to check it happens)
                            -3 a cgi app that just writes a file

                            How many problems do you have? 2?



                            ------------------
                            Paul Dwyer
                            Network Engineer
                            Aussie in Tokyo

                            Comment


                            • #15
                              Finally had to come back to this problem.

                              I've tried everything to use URLDOWNLOADTOFILE with no luck.

                              After searching I found a function URLDownloadToString

                              After testing it works a treat. I've posted the working source code here

                              http://www.powerbasic.com/support/pb...110#post356110

                              Comment


                              • #16
                                >surl = "http://www.powerbasic.com"

                                Is that a file? Or does it have to be surl = "http://www.powerbasic.com/index.html"

                                ??

                                Don't understand why no error code. Maybe I should try that.

                                MCM

                                Comment


                                • #17
                                  It worked here, as posted.

                                  PB/CC 5.0.2, Win XP/Pro SP3 all updated, from IDE "compile and execute."
                                  Code:
                                  Microsoft Windows XP [Version 5.1.2600]
                                  (C) Copyright 1985-2001 Microsoft Corp.
                                  
                                  D:\Software_Development\pbcc50\Work>dir *.htm
                                   Volume in drive D has no label.
                                   Volume Serial Number is 049A-2E6F
                                  
                                   Directory of D:\Software_Development\pbcc50\Work
                                  
                                  11/06/2010  04:37 PM            68,970 test.htm
                                                 1 File(s)         68,970 bytes
                                                 0 Dir(s)  61,322,919,936 bytes free
                                  
                                  D:\Software_Development\pbcc50\Work>
                                  Test.htm looks like..
                                  Code:
                                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
                                  <html>
                                  <head>
                                    <title>PowerBASIC: Basic Compilers</title>
                                    <meta name="keywords"
                                   content="power basic compiler, powerbasic downloads, BASIC programming, pbdll, turbo basic, qbasic compiler, visual basic, vb">
                                    <meta name="description"
                                   content="Welcome to PowerBASIC! Shop online for PowerBASIC compilers, BASIC compilers and programming tools for Windows and DOS.  Extensive tech support and peer support forums available.">
                                    <meta http-equiv="pics-label"
                                   content="(pics-1.1 &quot;http://www.icra.org/ratingsv02.html&quot; l gen true for &quot;http://www.powerbasic.com&quot; r (cz 1 lb 1 lc 1 nz 1 oz 1 vz 1) &quot;http://www.rsac.org/ratingsv01.html&quot; l gen true for &quot;http://www.powerbasic.com&quot; r (n 0 s 0 v 0 l 2))">
                                  .....
                                  </script>
                                  <script type="text/javascript">
                                  _uacct = "UA-2383716-1";
                                  urchinTracker();
                                  </script>
                                  </body>
                                  </html>
                                  Did you look in the right directory?

                                  Try making "test.htm" fully-qualified (drive:\path\filename) so you can be sure of where you expect that file to be.

                                  MCM

                                  Comment


                                  • #18
                                    Hi,

                                    My guess is that test.htm is not written into the directory you expect. I would also suggest, like MCM, to specify the directory too.

                                    Cheers
                                    Steven
                                    So here we are, this is the end.
                                    But all that dies, is born again.
                                    - From The Ashes (In This Moment)

                                    Comment


                                    • #19
                                      Yes I tried that, also made sure that the permission was correct for IIS to write also. I've kind of given up with this function if favour of urldownloadtostring

                                      http://www.powerbasic.com/support/pb...wnloadtostring

                                      It works but seems a bit processor intensive and not so efficient as urldownloadtofile

                                      Comment


                                      • #20
                                        >It works but seems a bit processor intensive and not so efficient as urldownloadtofile

                                        I will bet you the computer is doing exactly the same amount of work either way.

                                        The only difference is who issues what command to do which part of the job.

                                        MCM

                                        Comment

                                        Working...
                                        X