Ruby Net :: SFTP不起作用,即使在它自己的示例代码上也是如此

时间:2010-09-29 01:25:24

标签: ruby

尝试使用Net :: SFTP 2.05版(似乎是最新版本)。但它甚至在自己的示例代码上都失败了(下面是http://net-ssh.rubyforge.org/sftp/v2/api/index.html)。域,用户和密码与我手动登录时相同。当我能走得那么远时,我会改变路径。

Net::SFTP.start('ftp.domain.com', 'user', :password => 'password') do |sftp|

    # upload a file or directory to the remote host
    sftp.upload!("/path/to/local", "/path/to/remote")

    # download a file or directory from the remote host
    sftp.download!("/path/to/remote", "/path/to/local")

    # grab data off the remote host directly to a buffer
    data = sftp.download!("/path/to/remote")

    # open and write to a pseudo-IO for a remote file
    sftp.file.open("/path/to/remote", "w") do |f|
      f.puts "Hello, world!\n"
    end

    # open and read from a pseudo-IO for a remote file
    sftp.file.open("/path/to/remote", "r") do |f|
      puts f.gets
    end

    # create a directory
    sftp.mkdir! "/path/to/directory"

    # list the entries in a directory
    sftp.dir.foreach("/html") do |entry|
      puts entry.longname
    end
  end

它挂在第一行,回溯在下面(第14行是Net :: SFTP.start行)......

    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:801:in `block in loop'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:212:in `preprocess'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:197:in `process'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `block in loop'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `loop'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `loop'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
    c:/ruby192/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp.rb:35:in `start'
    C:/Data/dev/Ruby/RubyProjects/FTP_test/lib/ftp_test.rb:14:in `<top (required)>'

Windows 7,netbeans 6.9.1,ruby 1.9.2。示例代码来自自述文件..

1 个答案:

答案 0 :(得分:2)

当我在Perl中使用Net :: SFTP时,我遇到了类似的问题,而且它的sos路径没有正确设置。 你能检查一下SSH是否在路径中。 我知道答案与Ruby无关,但建议将其作为一般性观察。