Computer Science Canada

Downloading a file from the internet

Author:  skootles [ Thu Jan 26, 2006 11:35 am ]
Post subject:  Downloading a file from the internet

Hey, I'm just wondering if it's possible in turing to download a file from the internet? I wanted to have a section in my program that would download the latest update when you click a button, but I haven't had any experience with Turing and the internet.. so is it possible?

Author:  neufelni [ Thu Jan 26, 2006 11:59 am ]
Post subject: 

code:
if not Sys.Exec ("http://www.google.com"/*put any website here */) then
    put "Error"
end if
[/quote]

Author:  skootles [ Thu Jan 26, 2006 12:07 pm ]
Post subject: 

Thanks Very Happy , that will work, but I'm just wondering how would I use that to download .txt and image files too? Because when I just use that, they open up in IE.

Author:  Tony [ Thu Jan 26, 2006 12:58 pm ]
Post subject: 

You'd have to use the Net. module like over here

Author:  skootles [ Thu Jan 26, 2006 1:53 pm ]
Post subject: 

Alrighty, well I have this, which should download a google image (just for testing purposes):
code:
var url : string := "http://mail.google.com/mail/help/images/logo.gif"

var count : int := 0
var progress : int
var netStream : int
var net_line : char

netStream := Net.OpenURLConnection (url)

if netStream <= 0 then
    put url, " could not be located."
    return
end if

var filenum : int
open : filenum, "test.gif", write

loop
    exit when eof (netStream)
    count += 1
    locate (1, 1)
    progress := round ((62000 - count) / 1000)
    put "Downloading Count Down:", progress
    get : netStream, net_line
    write : filenum, net_line
   
end loop

Net.CloseConnection (netStream)


I just did a quick mod to that other program. I just don't know why this doesn't work Sad

Author:  r0ssar00 [ Thu Jan 26, 2006 2:56 pm ]
Post subject: 

whats the error message, something about illegal char in string, if im correct?

Author:  skootles [ Thu Jan 26, 2006 3:01 pm ]
Post subject: 

Sorry for double post, but I get an error in the bottom right of my screen that says "General Protection (seg" (it gets cut off) that displays for about a milisecond, then the program terminates.. I really have no clue whats going wrong Embarassed

Author:  Tony [ Thu Jan 26, 2006 9:20 pm ]
Post subject: 

a crude approach to step-testing would be to paste your program into a new file one line at a time, and see how far your code works before you get your General Error

Once you know what line of code produces the error, it will be easier for you and others to figure out the cause

Author:  skootles [ Fri Jan 27, 2006 12:53 am ]
Post subject: 

Hmm.. Well, when I run the original program:
code:
procedure playMP3
    loop
        Music.PlayFile ("test.mp3")
    end loop
end playMP3

procedure streamMP3 (url : string)
    var count : int := 0
    var progress : int
    var netStream : int
    var net_line : char
    netStream := Net.OpenURLConnection (url)
    if netStream <= 0 then
        put "Unable to download mp3 ", url, "!"
        return
    end if
    var fileNo : int
    open : fileNo, "test.mp3", write
    loop
        exit when eof (netStream)
        count += 1
        locate (1, 1)
        progress := round ((62000 - count) / 1000)
        put "Downloading Count Down:",progress
        get : netStream, net_line
        write : fileNo, net_line
    end loop
    Net.CloseConnection (netStream)
    close : fileNo
    playMP3
end streamMP3

streamMP3 ("http://72.29.76.231/~eclipti/turing/test.mp3")

I get the error that appeared in the bottom of my screen, but as a regular turing error. (The error is "General protection (segmentation) fault", and it highlights the line "Net.CloseConnection (netStream)".

When I run "my program", and trace it, it stops at "exit when eof (netStream)", and it doesn't terminate the program.

Author:  skootles [ Fri Jan 27, 2006 12:54 am ]
Post subject: 

Whoops, forgot that I had over half of it commented Razz
When I trace it, it give me the same error as the other program.

Author:  ecliptical [ Sat Jan 28, 2006 11:44 pm ]
Post subject: 

The error you're having is a turing enternal error...i wrote my own GetUrl Module sending my own HTTP headers and everything and accessing Google still crashed turing...if you're testing it's best not to test with Google...use some other website...i know yahoo works...

Author:  Tony [ Sun Jan 29, 2006 1:35 am ]
Post subject: 

some sites (including CompSci.ca) check to see if connection is made by a browser (FireFox, Safari, IE, etc) or a bot, and respond differently. Turing's request would be identified as a bot, and some sites might break on you.

Author:  skootles [ Sun Jan 29, 2006 1:58 am ]
Post subject: 

Ahh, that makes sense. However, I used to have a program like this in VB, that did the same thing. I accidentally deleted the project files, but I wanted to try and make it in a language I know fairly well anyways. Part of that program downloaded sets of image files (from my hosting), and when I tried downloading the same sets, it didn't work. So wouldn't it have detected the other program as a bot?

Author:  Tony [ Sun Jan 29, 2006 2:02 am ]
Post subject: 

I can't say for sure

you could test things out locally by setting up your computer to act as a server. This way you know exactly what's happening on serverside as well

Author:  skootles [ Sun Jan 29, 2006 2:08 am ]
Post subject: 

Well, that sounds like it would take some advanced knowledge.. so I don't think it would do me any good unfortunately.

Author:  Dan [ Sun Jan 29, 2006 2:09 am ]
Post subject: 

I am not shure what the anti-bot software whould do when it sees turing, i never consired it when making the security. Just do not put it in a loop trying to access somthing form compsci.ca b/c if it dose think u are a bot and thinks u are trying to DoS it may bite back Razz

Author:  skootles [ Sun Jan 29, 2006 2:15 am ]
Post subject: 

*writes note and sticks to monitor*

"NEVER access compsci.ca in a loop"

Aha...

Author:  Dan [ Sun Jan 29, 2006 2:45 am ]
Post subject: 

LOL, well it whold not be that bad whould just redirect your DoS back at you witch whould just hit u as hard as it was hiting compsci.ca. At worst it whould crash your comp.

Author:  skootles [ Sun Jan 29, 2006 11:58 am ]
Post subject: 

Ah well I don't know how to DoS anything anyways, so I guess I'm safe Razz

Author:  ecliptical [ Sun Jan 29, 2006 11:39 pm ]
Post subject: 

Also what helps sometimes is if you use the direct IP/~path to your hosting...(assuming it's not free) usually hosting services have those.

Author:  [Gandalf] [ Mon Jan 30, 2006 3:51 am ]
Post subject: 

skootles wrote:
Ah well I don't know how to DoS anything anyways, so I guess I'm safe Razz

Well, requesting something from a host for a long time (ie. in a loop) could be considered DoSing (Denial of Service). You don't always have to know what something is to do it. Smile


: