Mock 32 #1 Posted November 25, 2009 (edited) Eu fiz apenas brincando isso no começo, eu nao sabia da possibilidade do io.open abrir arquivos com wb e rb e por isso quando fiz apenas fazia download te textos agora graças ao nosso amigo colex eu fiz um que baixa qualquer arquivo* Ainda tem ums pogs aki eu fiz e nem revisei o code eu fiz testei tirei algums probleminhas e pronto ta feliz E uma funçao naverdade... downloadFile(IP,PORT,fileRequested,outputname[,bytes,delay,htmlVer]) Um exemplo: downloadFile('img6.imageshack.us',80,'img6/7580/aaanz5.jpg','q.jpg') Ele vai baixar o arquivo http://img6.imageshack.us/img6/7580/aaanz5.jpg que é nossa foto: [spoiler=foto] e vai salva-la com nome de q.jpg os params bytes,delay,htmlVer bytes vc pode escolher em quantos bytes pretende baixar por receive 1024, 2048 1 byte... delay e caos queira colocar um delay entre cada receive e esse htmlver e pra alguns webservers que ficam de pirraça quando vc manda html 1.1 ele so aceita 1.0 ou vice e versa xP Olha a funçao: require 'ex' require 'socket' function math.percent(v, t, f) --- By skyen hasus if f then return math.floor((v/t)*100) else return (v/t)*100 end end function downloadFile(IP,PORT,fileRequested,outputName, byte_s ,delay,htmlVer) --- Function by mock assert(fileRequested,'fileRequested is nil!') IP = IP or 'localhost' PORT = PORT or 80 local client = socket.connect(IP,PORT) print('Iiniciando download em: http//'..IP..':'..PORT..'/'..fileRequested..'/') if client then client:setoption('keepalive', true) client:send('GET /'..fileRequested..' HTTP/'..(htmlVer or '1.0')..'\r\n\r\n') local byte = 0 local findfile = false local star = os.clock() local file = io.open(outputName, "wb") if not file then print('Nao foi possivel criar '..fileRequested) return false end repeat r = client:receive(sizee) if r then if string.find(r,'Content%-Length:') then size = string.match(r,[[Content%-Length: (%d+)]]) or '??' print('Size:'..size) end end if r == "" then findfile = true print('Iniciando!') end if findfile == true and r then file:write(r) byte = byte+r:len() sizee = byte_s or 1048 os.sleep(delay or 0.001) per = math.percent(byte, size or 100,1) if per ~= old then print(byte..'/'..(size or '?'),per..'%') old = per end end until not r file:close() print('\aDownload finalizado em '..(os.clock()-star)..' segundos.') else print('Nao foi possivel conectar!') return false end return true end downloadFile('img6.imageshack.us',80,'img6/7580/aaanz5.jpg','q.jpg') Quando executar ela vai baxar a foto do imageshack automaticamente Ainda tem alguns bugs xP Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Gpwjhlkdcf 21 #2 Posted November 25, 2009 (edited) function math.percent(v, t, f) --- By skyen hasus if f then return math.floor((v/t)*100) else return (v/t)*100 end end Nem lembrava mais dessa função. Tá muito tosca, muda ela ._.' Edited January 23, 2011 by Mickfern Share this post Link to post Share on other sites
Dark Billie 0 #3 Posted November 25, 2009 ursinho você podia colocar umas explicações das funções da OTAL para ficar de mais fácil entendimento, fui no site lá só via coisa que nem entendia rs Share this post Link to post Share on other sites
Mock 32 #4 Posted November 25, 2009 @Dark Billie qq a otal tem aver com isso? ._. Share this post Link to post Share on other sites
Dark Billie 0 #5 Posted November 26, 2009 cheio de poo que eu ñ entendo Share this post Link to post Share on other sites
Colex 0 #6 Posted November 26, 2009 faltava só uma letrinha ficou legal o resultado Share this post Link to post Share on other sites
Kaotar 5 #7 Posted April 10, 2010 (edited) A so pra lembrar, não funcionou aqui =/ que tristeza, na veradade eu não sei por que, vamo se disser quando você baixa um arquivo .rar ele baixa e etc, mas quando vai abrir diz que deu um erro inesperado, não sei bem pq, o tamanho é igual e etc. Mas tudo bem Flws EDIT: Ops, percebi que falta algum numero de bytes, entre o baixado por isso e pelo baixado pelo Browser vo ver se resolvo Edited April 10, 2010 by Kaotar Share this post Link to post Share on other sites
Mock 32 #8 Posted April 10, 2010 @Kaotar essa funçao é pog puro nem use Share this post Link to post Share on other sites
Mickfern 32 #9 Posted April 10, 2010 Ai Mock, eu sei que voce pois ali, mas gostaria de saber se realmente pode baixar qualquer coisa ? Tipo não precisa ser coisas para ot's ( que nem a otal, que voce instala no server ) e sim, se pode baixar, por exemplo, filmes, etc... Share this post Link to post Share on other sites
Mock 32 #10 Posted April 15, 2010 @Mickfern naoi cara isso é apenas uma tentativa de fazer um script p baxa coisas usando lua, so q é mais lento que tudo isso ai Share this post Link to post Share on other sites
Fucknerds 0 #11 Posted April 20, 2010 Poderia me esplicar mais a função dele ? GRATO ;D Share this post Link to post Share on other sites