【问题标题】:Unable to connect using net/ftp in ruby无法在 ruby​​ 中使用 net/ftp 进行连接
【发布时间】:2014-03-31 05:19:54
【问题描述】:

当我尝试连接 FTP 服务器时出现以下错误

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)

我可以使用ftp://example.sg 从浏览器访问同一个网站。 任何想法为什么 net/ftp 会在访问该站点时遇到问题?

【问题讨论】:

    标签: ruby jruby net-ftp


    【解决方案1】:

    使用 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,但这应该没关系:-)

    【讨论】:

      猜你喜欢
      • 2011-07-06
      • 2011-10-13
      • 2021-07-23
      • 2010-12-20
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      相关资源
      最近更新 更多