I have part of the code which is to get the binary file stream from one FTP server.
It works on my Ubuntu but the code cannot get the binary file from the FTP server when I tried it on the Amazon EC2 instance.
I tried to switch to another gem called open-uri. It can get the binary file stream on both my local PC and remote EC2 instance.
I use the default VPC of EC2 instance.
I already opened port 20 and 21 on EC2. I used dig ftp.cga.ct.gov
and there is a answer on EC2.
If there is some point which is not clear for your guys, please point it out
Here is my code in the initialize method of one Ruby class:
def initialize(session_id)
@session_id = session_id
@count = 1
tries = 10
begin
ftp = Net::FTP.new("ftp.cga.ct.gov")
ftp.read_timeout = 500
ftp.login
ftp.chdir('/pub/data/')
bill_str= ftp.getbinaryfile("bill_info.csv", nil)
@bill_array = bill_str.delete("\"").split("\r\n")[1..-1]
rescue Exception => e
if (tries -= 1) > 0
sleep 10
print "re-connect"
retry
else
print "Cannot open FTP\nThe error message is #{e}\n#{e.backtrace.join("\n")}"
end
else
return true
end
super
end
I think it is totally because of Amazon internal subnet bugs. Check my other question and the answer from myself.