Jump to content
Sign in to follow this  

Downloading a file from the n bytes position

Recommended Posts


Hi, I was wondering if it would be possible to download a file from a certain byte position. What I mean is to download the file without (for example) download the first 200 kbytes?

The purpose of it for example would be to download the Tag informations from an mp3 (last 128 bytes of the file if I remember correctly) without having to download the whole file...

Any idea how to do that?

Share this post

Link to post
Share on other sites


See the example in the zip linked from my signature; APITailRW

Best, randall


Share this post

Link to post
Share on other sites

@randallc : ok I got it about fast reading/writing at any place in a local file, but I would like to do the same from a remote file without downloading the whole file but just the few bytes that I want to use/read. As you can resume a download I think it must be possible to start the download from a n bytes position... I check the http protocol but couldn't find that I wanted...

Ok... I finally found something in the HTTP/1.1 RFC, http://www.w3.org/Protocols/rfc2616/rfc261...4.html#sec14.35

Edited by JavaCupiX

Share this post

Link to post
Share on other sites

Maybe my researches will help someone so I post the few lines I put together (thanks to Overload for his HTTP UDF), this lines allow you to download the wanted bytes from a remote file using the HTTP protocol (works depending on the server configuration).

Dim $address = TCPNameToIP("www.google.fr")

Dim $socket = -1
$socket = TCPConnect($address, 80)

If @error Then
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
    $command = "GET /intl/fr_fr/images/logo.gif HTTP/1.1"&@CRLF
    $command &= "Range: bytes=75-77" & @CRLF
    $command &= "Host: www.google.fr"  & @CRLF
    $command &= "Connection: close"&@CRLF
    $command &= ""&@CRLF
    TCPSend($socket, $command)
    While 1
        ; Try to receive (up to) 10 bytes (as we mix up binary and string data this should be small so that they don't mix up)
        $recv = TCPRecv( $socket, 10 )
        ; If the receive failed with @error then the socket has disconnected
        If @error Then ExitLoop
        ; Output to console the received content
        If $recv <> "" Then ConsoleWrite($recv)

This downloads the bytes 75, 76, 77 from the google logo and prints it to the console (with protocol informations).

Very experimental stuff as I tested it on an internal server and not on the internet as my proxy is screwing around...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this