Announcement

Collapse
No announcement yet.

URLDownloadToFile and Zero-Byte File

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

  • URLDownloadToFile and Zero-Byte File

    I've used URLDownloadToFile for years now, but never noticed that it will not create a file on the PC if the URL points to a zero-byte file. The return value says the API completed successfully, but a zero-byte local file is not created.

    This code does not create a local file if the URL points to a zero-byte file, but does if the URL is not a zero-byte file.

    Code:
    #Compile Exe
    %Unicode = 1
    #Include "Win32API.inc"
    #Include "WinInet.inc"
    
    Function PBMain() As Long
       Local iResult As Long
       iResult = URLDownloadToFile(Nothing, "http://www.garybeene.com/clipboard/binaryfilename.txt", "c:\data\gbapps\gbNetBoard\temp\binaryfilename.txt", 0, Nothing)
       ? Str$(iResult)
    End Function
    I did the obligatory Google search but did not find a reference to the problem. Has anyone else experienced the problem?

  • #2
    Has anyone else experienced the problem?
    Sounds to me like it's a pretty efficiently designed and implemented function: when it has nothing to do, it does nothing.

    Sorry, I cannot call this a "problem."

    Michael Mattias
    Tal Systems Inc.
    Racine WI USA
    mmattias@talsystems.com
    http://www.talsystems.com

    Comment


    • #3
      Michael Mattias That's very superficial and one dimensional thinking.

      A zero byte file can be extremely important. Not only is data valuable, but metadata can be just as much, if not more. Take logging for instance... if a 0 byte log file was created, that could indicate logging was working but there was nothing to log that day. The fact a file was created, it's name, and it's timestamp can all be extremely important pieces of information in some circumstances. Especially in the forensics field.

      If the function action stated by Gary is true then I say it's an error, because it failed to copy a completely valid file... zero bytes or not. A "success" return when the call did not do what it's intended function states is an error. I'll caveat that with "as long as it is not documented as such" then it is an error.
      Last edited by George Bleck; 11 Jan 2017, 11:25 AM. Reason: Because my grammar/spell-checking stinks.
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment


      • #4
        MCM, you more than most should grok the difference between a nul value and a zero value.
        "Not my circus, not my monkeys."

        Comment


        • #5
          Hey Gary,

          Not exactly what you got, but interesting...
          URLDownloadToFile : URLDownloadToFile returns S_OK even if the file cannot be created and the download is canceled.

          Pierre

          Comment


          • #6
            I have been on systems which will not create (retain?) a zero-byte file. I don't know if that was something in the O/S or maybe some service running which just deleted them as they occurred. (but I ran into this on two separate clients' systems).

            But being an "applications guy": (versus a"Tools and Utilities guy") my thinking is, "no data, so why even bother?"

            Seems totally natural to me. As far as storing applications data in the file Metadata... well, let's just say that would not make my short list for "Plan of the Year."

            But let me get back on topic and help Gary solve his "problem:" Well, now you know; deal with it.

            MCM
            Michael Mattias
            Tal Systems Inc.
            Racine WI USA
            mmattias@talsystems.com
            http://www.talsystems.com

            Comment


            • #7
              Hey Gary,

              Might be a good occasion to incorporate a IBindStatusCallback in your code...

              Pierre

              Last edited by Pierre Bellisle; 11 Jan 2017, 12:07 PM.

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                As far as storing applications data in the file Metadata... well, let's just say that would not make my short list for "Plan of the Year."
                You're making a false assumption that people are using the metadata as data storage, far from it. But, the metadata can be important or useful, regardless of the size of or content of the data it describes.

                The fact a file exits CAN be important
                The name of a file a CAN be important
                The fact a file has a certain date (either created/last written/last accessed) CAN be important

                I doubt anyone in their right mind creates a zero byte file on purpose just to store data in the filename/etc. or leave a mark with it's timestamp, but that does not mean it's not useful when it happens. Just because you do not see merit in it does not mean it does not have merit.

                Eliminating all of the above, and according to your own rules of engagement, it is undocumented behavior, therefore it should either be documented or called out as an error. The function is used to transfer a file, period, that''s it's job. What gives a function the right to decide if the file is valid or not (if undocumented to do so)? Only the caller can.decide if the file has value.
                Last edited by George Bleck; 11 Jan 2017, 01:51 PM.
                <b>George W. Bleck</b>
                <img src='http://www.blecktech.com/myemail.gif'>

                Comment


                • #9
                  The fact a file exits CAN be important
                  The name of a file a CAN be important
                  The fact a file has a certain date (either created/last written/last accessed) CAN be important
                  If I wanted to know those things, I'd just call InternetOpenUrl() for the directory followed by InternetFindNextFile() to get the existence, size and and date info instead of UrlDownloadToFile.

                  If one knows only the hammer, all challenges look like nails.
                  Michael Mattias
                  Tal Systems Inc.
                  Racine WI USA
                  mmattias@talsystems.com
                  http://www.talsystems.com

                  Comment


                  • #10
                    You're confusing the nature of the file with the action of the function. YOU may not want to know the info associated with the file but someone down the line may. You are forcing your PERSONAL wants and needs when they need not apply.

                    This isn't about silly inapplicable hammer and nail metaphors, but about a function that does not do what is supposed to, that is, simply, to transfer the requested file. A zero byte file is a valid file-period, the end,-regardless of the reason why it exists, if it has any meaning, or if YOU think it should be transferred or not.
                    <b>George W. Bleck</b>
                    <img src='http://www.blecktech.com/myemail.gif'>

                    Comment


                    • #11
                      > As far as storing applications data in the file Metadata...
                      > well, let's just say that would not make my short list for "Plan of the Year."

                      Thanks! I'll pass that along to the members of the team that (20+ years ago) designed the 11.5 million files that I am currently downloading with wget* from a government database. Sheesh, Michael, lots of people work under circumstances that are less ivory than yours.

                      BTW it wasn't their "plan" to use zero-length files; I am harvesting data -- including metadata -- and I'll take it any way I can get it.

                      *vastly popular commandline tool (which downloads zero-length files with intact metadata).


                      "Not my circus, not my monkeys."

                      Comment


                      • #12
                        I'll pass that along to the members of the team that (20+ years ago) designed the 11.5 million files that I am currently downloading..
                        We all did weird things twenty years ago.

                        We all promised ourselves - and sometimes others - we'd un-weird them just as soon as we had a good chance to do so.

                        None of us ever did.
                        Michael Mattias
                        Tal Systems Inc.
                        Racine WI USA
                        mmattias@talsystems.com
                        http://www.talsystems.com

                        Comment


                        • #13
                          The consensus conclusion being that Gary was correct in calling it a "problem".
                          "Not my circus, not my monkeys."

                          Comment


                          • #14
                            One man's problem is another man's opportunity.
                            Michael Mattias
                            Tal Systems Inc.
                            Racine WI USA
                            mmattias@talsystems.com
                            http://www.talsystems.com

                            Comment

                            Working...
                            X