tags:

views:

56

answers:

1

Trying to use Net::SFTP, version 2.05 (appears to be the latest). But it fails even on its own sample code (below, from http://net-ssh.rubyforge.org/sftp/v2/api/index.html). The domain, user and password are the same as I use to log in manually. I will change the paths when I can get that far.

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

It hangs on the first line, and the traceback is below (line 14 is the Net::SFTP.start line)...

    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. The sample code is from the readme at..

A: 

When i used Net::SFTP in Perl i faced similar issue and its becos ssh path was not set properly. Can you check whether SSH is in path. I know the answer is not related to Ruby but suggested this as a general observation.

Raghuram
yep, make sure first you can ssh from the command line and connect to the remote server.
Jed Schneider
Yes, I can connect with SSH manually (using PuTTY), and I make sure to use the same credentials in the ruby code. Could there be an issue with the key?
David Lewis
I tried a different site where I am 100% sure of the credentials and folder structure -- and it worked. I probably messed up on the first try. Sorry for the alarm.
David Lewis