我正在尝试创建一个脚本来使用 Ruby 从 FTP 服务器列出和下载数据。我是 Ruby 新手,所以我查找了如何使用 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 >建立连接失败。(网络::FTPTempError) 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:325:in `block in sendcmd' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:323:in `sendcmd' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:402:in `transfercmd' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:478:in `retrlines 中的块(2 级)' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:178:in `with_binary' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:477:in `block in retrlines' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:476:in `retrlines' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:722:in `list' 来自 test_ftp.rb:10:in `block in ' 来自 /home/adhown/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/ftp.rb:116:in `open' 来自 test_ftp.rb:8:in `'
谁能解释我的脚本有什么问题?