![](/img/trans.png)
[英]Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance
[英]Cannot get binaryfile using Ruby from one FTP server under Amazon EC2 instance
我有一部分代碼是從一個 FTP 服務器獲取二進制文件流。
它適用於我的 Ubuntu,但當我在 Amazon EC2 實例上嘗試時,代碼無法從 FTP 服務器獲取二進制文件。
我嘗試切換到另一個名為 open-uri 的 gem。 它可以在我的本地 PC 和遠程 EC2 實例上獲取二進制文件流。
我使用 EC2 實例的默認 VPC。
我已經在 EC2 上打開了端口 20 和 21。 我使用dig ftp.cga.ct.gov
並且在 EC2 上有答案。
如果小伙伴們有什么不明白的地方,請指出
這是我在一個 Ruby 類的 initialize 方法中的代碼:
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
我認為這完全是因為亞馬遜內部子網的錯誤。 檢查我的另一個問題和我自己的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.