0

I am getting following error when I am trying to connect the FTP server

ftp = Net::FTP::new("example.sg","username","password")
Errno::ECONNREFUSED: Connection refused - Connection refused
   from org/jruby/ext/socket/RubyTCPSocket.java:121:in `initialize'
    from org/jruby/RubyIO.java:876:in `new'
    from org/jruby/ext/socket/RubyTCPSocket.java:147:in `open'
    from /opt/jruby/lib/ruby/1.8/net/ftp.rb:159:in `open_socket'
    from /opt/jruby/lib/ruby/1.8/net/ftp.rb:175:in `connect'
    from /opt/jruby/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize'
    from /opt/jruby/lib/ruby/1.8/net/ftp.rb:174:in `connect'
    from /opt/jruby/lib/ruby/1.8/net/ftp.rb:136:in `initialize'
    from (irb):7:in `evaluate'
    from org/jruby/RubyKernel.java:1083:in `eval'
    from /opt/jruby/lib/ruby/1.8/irb.rb:158:in `eval_input'
    from /opt/jruby/lib/ruby/1.8/irb.rb:271:in `signal_status'
    from /opt/jruby/lib/ruby/1.8/irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1410:in `loop'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /opt/jruby/lib/ruby/1.8/irb.rb:154:in `eval_input'
    from /opt/jruby/lib/ruby/1.8/irb.rb:71:in `start'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /opt/jruby/lib/ruby/1.8/irb.rb:70:in `start'
    from /opt/jruby/bin/jirb:13:in `(root)

I am able to access the same website from a browser using ftp://example.sg. Any ideas why net/ftp would have issues accessing the site?

4

1 回答 1

0

使用 JRuby 1.7.4 工作:

Welcome to the JRuby IRB Console [1.7.4 (1.9.3)]

irb(main):001:0> require 'net/ftp'
true
irb(main):002:0> ftp = Net::FTP.new('ftp.ruby-lang.org', 'anonymous', '')
#<Net::FTP:0x4e2d4656 @mon_count=0, @mon_owner=nil, @logged_in=true, @sock=#<TCPSocket:fd19>, @last_response="200 Switching to Binary mode.\n", @last_response_code="200", @passive=false, @resume=false, @binary=true, @debug_mode=false, @welcome="230 Login successful.\n", @mon_mutex=#<Mutex:0x7e64e032>>
irb(main):003:0> ftp.list
["drwxrwxr-x    5 106      111          4096 Dec 25 23:42 pub"]

如果您尝试 ruby​​-lang.org 网站,它对您有用吗?

我看到您使用了,Net::FTP::new而不是Net::FTP.new,但这没关系:-)

于 2014-03-31T05:55:08.173 回答