Announcement

Collapse
No announcement yet.

URLDownloadToFile

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

    #21
    But could you clarify why you have the opinion? [why UrlDownLoadToFile] is an inferior design if tryint to monitor changes in a file over the Internet]
    Because you could use FTPFindFirstFile() to get the file timestamp in a WIN32_FIND_DATA structure instead of downloading the whole file and doing some kind of comparison at that time or simply willy-nilly replacing.

    Your definition of "inferior" may vary.

    Note: I am using older (outdated) doc. There may be even better ways available today, e.g., what you can do with FindFirstChangeNotification except with a directory path which is available via an internet connection


    BTW.... you might want to look at InternetSetOption/InternetGetOption against the (FTP) hInternet handle for option ....
    INTERNET_OPTION_CACHE_TIMESTAMPS Retrieves an INTERNET_CACHE_TIMESTAMPS structure that contains the LastModified time and Expires time from the resource stored in the Internet cache. This value is used by InternetQueryOption.
    ... as an alternate way of dealing with your cache timestamps.


    MCM

    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


      #22
      1) Is there a good packet sniffer to examine downloads to see if they are encrypted?

      2) Does UrlDownloadToFile automatically use TLS from an https site? It is never mentioned in the docs.

      3) Is there an UrlUploadtofile?
      If these are secure they could be used in client/server programs to eliminate TCP loops.
      They might be as fast since the files would be cached to both ends and this code is very fast.

      4) CBC mode is no longer considered secure and want to be sure GCM is used.
      If transferring files is fast and automatically encrypts will probably start using it with client/server programs.
      A server program could be modified to create files instead of sending/receiving using TCP.
      If multiple users make the same inquiry the recordset would be returned as a file (might even be in cache.)

      Dale, (see post #18)
      What you are looking for is the security code (as in PB source code).
      UrlDownload to file is not PB code. Does it need additional code for security with TLS?
      The WinHttpRequest code below works without adding security. Is it insecure from an https site?


      5) This code, Jose Roca code modified into a function will download from a protected page on an https site.
      Is data transferred in plain text?
      Code:
      #INCLUDE "httprequest.inc"
      ' https://forum.powerbasic.com/forum/jose-s-corner/source-code-ab/51694-winhhtp-com-examples
      %FALSE=0
      FUNCTION PBMAIN
       LOCAL wsFullPath,wsUsername,wsPassword,wsDataReturned,wsStatus AS WSTRING
       wsFullPath = "https://powerbasic.com/protectedfolder/protectedfile.exe"
       wsUserName = ""
       wsPassword = ""
       wsStatus= Download(wsFullPath, wsUserName, wsPassword,wsDataReturned)
       IF wsStatus = "OK" THEN
        ? USING$("Downloaded (#, bytes)",LEN(wsDataReturned)),%MB_SYSTEMMODAL,"Success"
       ELSE
        ? wsStatus,%MB_ICONERROR OR %MB_SYSTEMMODAL,"Download Failed"
       END IF
      END FUNCTION
      '===============================================================================================
      FUNCTION Download(wsFullPath       AS WSTRING,_
                    wsUserName           AS WSTRING,_
                    wsPassword           AS WSTRING,_
                    wsDataReturned       AS WSTRING) AS WSTRING
      
       RESET wsDataReturned
       DIM pHttpReq AS IWinHttpRequest
       pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
       IF ISNOTHING(pHttpReq) THEN
        ? "WinHttpRequest.5.1 failure",%MB_ICONERROR OR %MB_SYSTEMMODAL,"Download"
        EXIT FUNCTION
       END IF
       pHttpReq.Open "GET", wsFullPath, %FALSE
       pHttpReq.SetCredentials wsUserName, wsPassword, %HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
       pHttpReq.Send
       IF pHttpReq.StatusText <> "OK" THEN
        BEEP
       ELSE
        wsDataReturned = pHttpReq.ResponseText
       END IF
       FUNCTION = pHttpReq.StatusText
       pHttpReq = NOTHING
      END FUNCTION

      Comment


        #23
        ) Is there an UrlUploadtofile?
        The way I wrote this Source Code Forum demo it's pretty close. And anyway, What's in a name? That which we would call a rose by any other name would smell as sweet!

        WinInet FTP Upload (Overwrite or Append) Demo 3-10-08
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


          #24
          Looks good, but I don't have FTP servers.
          Still need to know if urldownloadtofile and the code I posted would be encrypted using TLS.

          Comment


            #25
            Hi Guys

            Interesting discussion - but a bit beyond my expertise

            I would like to offer a service where I spell check websites - amongst other things.

            So I would like to say 'please download onto file X all the contents of website Y'

            Can some kind guru tell me how to do that so that I understand?

            If there are issues with a few websites - well too bad, let us not worry about that.

            Thanks in advance.

            Kerry
            [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
            Kerry Farmer

            Comment


              #26
              1. Packet sniffer - WIreshark
              2. All HTTPS traffic uses TLS
              3. No, to upload a file, a web site must be running something like PHP to process the upload.
              4.See 2. above.
              5. See 2 above

              =========================
              https://camcopng.com
              =========================

              Comment


                #27
                Great news. Thank you!

                Comment


                  #28
                  Originally posted by Mike Doty View Post
                  Bob,
                  You are right. It is definitely working.with Windows 10.
                  Not sure what was going wrong a couple of years ago.
                  Updated my remarks in post #8.
                  Thank you!
                  Code:
                  #INCLUDE "win32api.inc"
                  #INCLUDE "wininet.inc"
                  FUNCTION PBMAIN()
                  LOCAL errcode AS LONG
                  LOCAL zurl AS ASCIIZ * 512
                  LOCAL zlocalfile AS ASCIIZ * 512
                  zurl = "https://www.dotysoftware.com/junk.exe" '200,000,000 bytes
                  mkdir "c:\mytest"
                  errclear
                  zlocalfile = "\mytest\junk.exe"
                  errcode = DeleteURLCacheEntry(zurl) '1=success, 0=failed
                  errcode = urlDownloadToFile(BYVAL 0,zurl,zlocalfile,0,0)
                  IF errcode = 0 THEN ? "Download ok" ELSE ? "Download error" + STR$(errcode)
                  END FUNCTION
                  The above example works fine with Win10 & 11 but when I try to run under Server 2016 I get

                  Download error-2146697208

                  Any suggestions?

                  Actually I've tried this on another installation of Server 2016 and no issues. Need to investigate a bit more.

                  Comment


                    #29
                    The file did not exist. Try it now.
                    It should not have worked.

                    Comment


                      #30
                      Originally posted by Mike Doty View Post
                      The file did not exist. Try it now.
                      It should not have worked.
                      Ah sorry I changed the url to https://djsuperstore.com/robots.txt

                      Bit balled why the primary domain controller goves the error and the secondry doesn't

                      Comment


                        #31
                        -2146697208 is 0x800c0008​
                        Can mean - Unable to write file.

                        > MKDIR C:\MyTest
                        Do you have the rights to create a folder in the root of drive C:\ on the problem server?

                        You create zlocalfile = "\mytest\junk.exe"
                        Are you running the program from drive C: ?
                        If you are running from from Drive E for example, you are creaing C:\MyTest but trying to write to E:\MyTest

                        Also, try changing to WSTRINGZ rather than STRINGZ and checking the return from CacheEntryDelete:

                        '
                        Code:
                        %UNICODE = 1
                        #INCLUDE "win32api.inc"
                        #INCLUDE "wininet.inc"
                        FUNCTION PBMAIN()
                        LOCAL errcode AS LONG
                        LOCAL zurl AS WSTRINGZ * 512
                        LOCAL zlocalfile AS WSTRINGZ * 512
                        zurl = "https://djsuperstore.com/robots.txt" '200,000,000 bytes
                        MKDIR "c:\mytest"
                        ERRCLEAR
                        zlocalfile = "C:\mytest\junk.exe"
                        errcode = DeleteURLCacheEntry(zurl) '1=success, 0=failed
                        IF errcode = 0 THEN ? "Cache entry deleted" ELSE ? "Can't delete cache entry" + STR$(errcode)
                        errcode = urlDownloadToFile(BYVAL 0,zurl,zlocalfile,0,0)
                        IF errcode = 0 THEN ? "Download ok" ELSE ? "Download error" + STR$(errcode)
                        END FUNCTION
                        '



                        Otherwise, check the firewall on the problem server.
                        =========================
                        https://camcopng.com
                        =========================

                        Comment


                          #32
                          >Can mean - Unable to write file.

                          Interesting...


                          urlmon.h - 0x800C0008L (-2146697208) INET_E_DOWNLOAD_FAILURE

                          Comment


                            #33
                            Originally posted by Pierre Bellisle View Post
                            >Can mean - Unable to write file.

                            Interesting...


                            urlmon.h - 0x800C0008L (-2146697208) INET_E_DOWNLOAD_FAILURE
                            Yes "can"

                            it's a very generic error whichh can have several causes.. It can mean that the file didn't exist or that the file couldn't be written or that there was a connectivity problem or ....

                            But given the issues identified in the OP's code and the fact that it is only happening on one machine, inability to write the file is a good first guess.

                            =========================
                            https://camcopng.com
                            =========================

                            Comment


                              #34
                              > it's a very generic error whichh can have several causes.. It can mean that the file didn't exist or that the file couldn't be written or that there was a connectivity problem or ....

                              If I may, do you have any Microsoft URL that confirm this.

                              Context is urlDownloadToFile > error is urlmon.h - 0x800C0008L (-2146697208) INET_E_DOWNLOAD_FAILURE

                              Comment


                                #35
                                Hello.

                                hanks for all of your replies.

                                I ran the program in #31 on my workstation and the directory was created and file downloaded.

                                When I ran on the server the directory was created but still error -2146697208

                                Does urlDownloadToFile use Internet explorer components?

                                Click image for larger version

Name:	screen_shot.jpg
Views:	167
Size:	86.0 KB
ID:	822992
                                The left dialog is the server that's failing and the right it's working ok. No matter what I try I'm unable to change the levels for the zone. I also tried adding to trusted sites and still failing.

                                Comment


                                  #36
                                  > The download of the specified resource has failed.

                                  > Does urlDownloadToFile use Internet explorer components?
                                  Do not know.

                                  Does this work?
                                  Syntax: wsFile = test("https://www.yoursite.com/yourfile.txt")

                                  Code:
                                  FUNCTION test(wsUrl AS WSTRING) AS WSTRING
                                    DIM sMethod AS WSTRING
                                    DIM oXml AS IServerXMLHTTPRequest2
                                    SET oXml = NEWCOM "MsXml2.ServerXMLHTTP.6.0"
                                    sMethod = "GET"
                                    IF ISTRUE(ISOBJECT(oXml)) THEN
                                        oXml.Open(sMethod, wsURL, %FALSE)
                                        oXml.Send()
                                        DO WHILE oXml.ReadyState<>4
                                            SLEEP 0
                                            ? "[" & STR$(oXml.ReadyState) & "]"
                                            ? "error exit function":EXIT FUNCTION
                                        LOOP
                                        FUNCTION= oXml.ResponseText
                                    ELSE
                                        ? "Unable to get version",,FUNCNAME$
                                    END IF
                                  END FUNCTION

                                  Comment


                                    #37
                                    Mike,

                                    Do you have a compilable example?

                                    Comment


                                      #38
                                      See post #22 (which is different.)

                                      Comment


                                        #39
                                        Code:
                                        #INCLUDE  "\roca\MSXML.INC" 'use Roca includes
                                        
                                        FUNCTION PBMAIN()
                                          LOCAL ws AS WSTRING
                                          ws = test("https://www.djsuperstore.com/robots.txt")
                                          ? ws
                                        END FUNCTION
                                        
                                        
                                        FUNCTION test(wsUrl AS WSTRING) AS WSTRING
                                          DIM sMethod AS WSTRING
                                          DIM oXml AS IServerXMLHTTPRequest2
                                          SET oXml = NEWCOM "MsXml2.ServerXMLHTTP.6.0"
                                          sMethod = "GET"
                                          IF ISTRUE(ISOBJECT(oXml)) THEN
                                              oXml.Open(sMethod, wsURL, %FALSE)
                                              oXml.Send()
                                              DO WHILE oXml.ReadyState<>4
                                                  SLEEP 0
                                                  ? "[" & STR$(oXml.ReadyState) & "]"
                                                  ? "error exit function":EXIT FUNCTION
                                              LOOP
                                              FUNCTION= oXml.ResponseText
                                          ELSE
                                              ? "Unable to get version",,FUNCNAME$
                                          END IF
                                        END FUNCTION


                                        Comment


                                          #40
                                          Seems that internet explorer enhance security function was enabled.

                                          Setting changed, log off and on again.

                                          All is well!

                                          Comment

                                          Working...
                                          X
                                          😀
                                          🥰
                                          🤢
                                          😎
                                          😡
                                          👍
                                          👎