Ruby Net-SFTP not responding

I am trying to upload a file to an SFTP site using Net :: SFTP.

The problem is that the Ruby process never returns. It froze, stuck, never ended ... I have Ctrl-C to stop it.

  • I can connect to the ftp server at the command line using sftp.
  • I tried this code on Linux (Ubuntu) and Snow Leopard, and it does the same.
  • The latest version of Net :: SSH and Net :: SFTP is installed.
    • From gem list net :
      • net-sftp (2.0.5)
      • net-ssh (2.1.4)
  • Various combinations of hash arguments (see code below)
  • Tried to call Net::SFTP.start instead of creating an SSH session first.
  • The server responds with " SFTP protocol version 3 " when I log in using the command line tool and request a version.
  • I am running Ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.7.0]

Debug output from :verbose (last couple of lines):

 D, [2011-07-29T17:30:52.692192 #19399] DEBUG -- tcpsocket[80c06478]: read 36 bytes D, [2011-07-29T17:30:52.692609 #19399] DEBUG -- tcpsocket[80c06478]: received packet nr 7 type 99 len 12 I, [2011-07-29T17:30:52.692751 #19399] INFO -- net.ssh.connection.session[80bd5da0]: channel_success: 0 D, [2011-07-29T17:30:52.692817 #19399] DEBUG -- net.sftp.session[80bd5c24]: sftp subsystem successfully started D, [2011-07-29T17:30:52.693625 #19399] DEBUG -- tcpsocket[80c06478]: queueing packet nr 8 type 94 len 28 D, [2011-07-29T17:30:52.693834 #19399] DEBUG -- tcpsocket[80c06478]: sent 52 bytes 

Code example:

 require 'rubygems' require 'net/sftp' FTP = "someftpsite" FTP_USER_NAME = "user" FTP_PASSWORD = "password" hash = {:password => FTP_PASSWORD, :verbose => :debug, :keys=>[""],:auth_methods => ["password"], :timeout => 5, :port=>22} begin Net::SSH.start(FTP,FTP_USER_NAME, hash) do |test| test.sftp.upload!("localfile","remotefile") end rescue Exception => err puts "error:#{err.inspect}" end 

Edit: 8/22/2011

This is similar to the interactivity of an SFTP server. I solved this by creating a shell script using wait and crawl from Ruby to run the file. A shell script is created at runtime. It seems really hacky, but this is the only way I was able to get it to work with Ruby. If anyone has a suggestion, I would like to find a better way to do this.

+4
source share
1 answer

Instead, you can use public / private key authentication. http://net-ssh.rubyforge.org/ssh/v1/chapter-2.html#s2

+1
source

All Articles