From: Quintus Date: 2010-12-21T04:43:31+09:00 Subject: Re: downloading a file Am 20.12.2010 19:19, schrieb Rajinder Yadav: > i tired using open-uri, but when i read and then save the file it mess > up the file? something like this > > require 'open-uri' > url = 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz' > file = open(url) > c = file.read > > f = File.open('openssl-1.0.0c.tar.gz', 'w') > f.write c > f.close Try file = open(url, "rb") instead of file = open(url) and f = File.open('openssl-1.0.0c.tar.gz', 'wb') instead of f = File.open('openssl-1.0.0c.tar.gz', 'w') . You're downloading a binary file, and Ruby will do bad things to newlines in it if you don't pass the "b" for binary. Additionally you should have a look at the block form of #open. Vale, Marvin