Skip to content

Instantly share code, notes, and snippets.

@servel333
Last active July 30, 2022 14:26
Show Gist options
  • Save servel333/6642770 to your computer and use it in GitHub Desktop.
Save servel333/6642770 to your computer and use it in GitHub Desktop.
Basic Ruby implementation of wget to fetch a file from the internet.
def wget(url,file)
require 'net/http'
require 'uri'
if (!file)
file = File.basename(url)
end
url = URI.parse(url)
Net::HTTP.start(url.host) do |http|
resp = http.get(url.path)
open(file, "wb") do |file|
file.write(resp.body)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment