我正在嘗試創建一個腳本來列出並使用Ruby從FTP服務器下載數據。我是Ruby新手,所以我查找了如何使用Net :: FTP的文檔。我很難理解爲什麼這不起作用:爲什麼Net :: FTP無法連接到服務器?
require 'net/ftp'
server = "ftp.server.com"
user = "myuser"
password = "mypassword"
Net::FTP.open(server, user, password) do |ftp|
files = ftp.chdir('mydirectory/')
files = ftp.list
puts "list out of directory:"
puts files
end
那也不行,返回此錯誤:
/home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:298:in `getresp': 425 >Failed to establish connection. (Net::FTPTempError) from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:325:in `block in sendcmd' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:323:in `sendcmd' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:402:in `transfercmd' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:478:in `block (2 levels) in retrlines' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:178:in `with_binary' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:477:in `block in retrlines' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:476:in `retrlines' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:722:in `list' from test_ftp.rb:10:in `block in ' from /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:116:in `open' from test_ftp.rb:8:in `'
誰能解釋一下有什麼不對我的腳本?
謝謝阿西什,我改變網:FTP模式爲被動,它的工作沒有我改變FTP服務器配置.. :) – adhown 2013-02-27 05:31:27
@adhown如果它幫助,那麼你應該接受答案。這樣做不僅不會增加您的聲譽,而且會確保人們持續響應您的查詢。 – saihgala 2013-02-28 09:32:28
@Ashish ..對不起Ashish我是新來的stackoverflow,我不明白你是什麼意思..我該怎麼辦? – adhown 2013-02-28 14:13:58