Downloading corrupted files

Hello,

I have created small program to download files from website. I am using
netbeans and JRuby. When I run program, it downloads files no problem,
however, if I run it outside netbeans, it downloads files of similar
size, but they are corrupted and compare by content shows many
differences.

Code:

def download_to_folder(folder, replay_name,id)
Dir.chdir(“D:\Starcraft\Replays\”+folder)
writeout = open(replay_name, “w”)
writeout.write(open(“http://www.sc2rep.com/replays/download?id=”+id.to_s).read)
writeout.close
end

Configuration (maybe it helps): Windows 7 64bit, Ruby 1.9.1-p243,
Netbeans 6.8 with JRuby 1.8.7 (2009-11-04 patchlevel 174) [java]

On 08/28/2010 02:44 AM, Paul Gilbert wrote:

def download_to_folder(folder, replay_name,id)
Dir.chdir(“D:\Starcraft\Replays\”+folder)
writeout = open(replay_name, “w”)
writeout.write(open(“http://www.sc2rep.com/replays/download?id=”+id.to_s).read)
writeout.close
end

Configuration (maybe it helps): Windows 7 64bit, Ruby 1.9.1-p243,
Netbeans 6.8 with JRuby 1.8.7 (2009-11-04 patchlevel 174) [java]

Try it with open(replay_name, “wb”) to open the file in binary mode.

-Justin

Justin C. wrote:

On 08/28/2010 02:44 AM, Paul Gilbert wrote:

def download_to_folder(folder, replay_name,id)
Dir.chdir(“D:\Starcraft\Replays\”+folder)
writeout = open(replay_name, “w”)
writeout.write(open(“http://www.sc2rep.com/replays/download?id=”+id.to_s).read)
writeout.close
end

Configuration (maybe it helps): Windows 7 64bit, Ruby 1.9.1-p243,
Netbeans 6.8 with JRuby 1.8.7 (2009-11-04 patchlevel 174) [java]

Try it with open(replay_name, “wb”) to open the file in binary mode.

-Justin

Wou, thanks a lot :slight_smile: