在ruby中可以使用net/ftp连接



尝试连接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访问网站会有问题吗?

使用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,但这应该无关紧要:-)

相关内容

  • 没有找到相关文章

最新更新