1

I am brand new to Ruby programming. Shortly after completing some free online lessons, I decided I wanted to complete a real world practical script.

I want to automate some file transfers using the SFTP protocol. I have installed the required gems (net-ssh, and net-sftp). But it appears I cannot connect to the server I am developing against. I am only trying to connect to the server with my script. I am not performing any SFTP commands. I have the following code:

    require 'rubygems'
    require 'net/ssh'
    require 'net/sftp'

    Net::SFTP.start('server_ip_address','username', password => 'password') do |sftp|
        puts "Connected!"
    end

I keep getting the following error:

C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.3.beta1/lib/net/ssh/transport/ses sion.rb:71:in `initialize': A connection attempt failed because the connected pa rty did not properly respond after a period of time, or established connection f ailed because connected host has failed to respond. - connect(2) for "(server_name)" port 22 (Errno::ETIMEDOUT)

I am able to connect to the SFTP server using FileZilla from my machine. I am developing from a Windows 7 64bit laptop, Ruby 2.2.0 installed.

Does anybody have any ideas on why I cannot connect to the remote server?

This is also my very first question on StackOverflow. If I did not list enough information, please let me know.

Thanks in advance.

  • Hi, have your customized your SSH port, maybe not 22? Or, you may check your SSH log on your server first. My CentOS server's default SSH log is at `/var/log/secure`, yours may be customized in `/etc/ssh/sshd_config` – ifyouseewendy Jun 23 '15 at 05:46
  • Thank you for the input @ifyouseewendy. I hadn't really considered the configuration on the remote server. It turns out I was trying to SFTP to a Windows server running FreeFTPd. I was unable to SSH to that server via a Putty session, so that does explain why my code cannot connect. I did switch my connection parameters to a Linux SFTP server and my code works! So I guess my next question is, would there be any way in Ruby to connect to a Windows box running SFTP hosting software? Perhaps this should be its own question? – Sean Farley Jun 25 '15 at 02:44
  • Haven't experienced connecting to a Windows SFTP, and maybe like you said, it's another question. Good luck :D – ifyouseewendy Jun 25 '15 at 09:58

0 Answers0