HTTP to FTP in Ruby


 

Example code of how you can get a file from a web server and then put it on a FTP-server.
The code has no error handling.


# HTTP2FTP.rb
# Mirror a webpage via FTP
# 2005-12-13 jonelf(a)gmail.com
require 'net/http'
require 'net/ftp'
require 'uri'
# init
host='http://www.plea.se/'
doc='thefile.txt'
url = URI.parse(host+doc)
ftpserver = 'hostname.domain.se'
user='dantyrell'
pwd='kungvarendakvall'
ftpdir='mirror'
# do it
tmpfile=File.new(doc,"w")
page=Net::HTTP.get url
tmpfile.puts page
ftp = Net::FTP.new(ftpserver,user,pwd)
ftp.chdir ftpdir
ftp.puttextfile(doc)