gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:10:55 24 4
gpt4 key购买 nike

尝试使用 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。示例代码来自 readme at..

最佳答案

当我在 Perl 中使用 Net::SFTP 时,我遇到了类似的问题,因为它的 ssh 路径设置不正确。你能检查 SSH 是否在路径中吗?我知道答案与 Ruby 无关,但建议这是一般性观察。

关于Ruby Net::SFTP 不工作,即使在它自己的示例代码中也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3818165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com