bnix / double-bag-ftps

Provides a child class of Net::FTP to support implicit and explicit FTPS.
MIT License
48 stars 26 forks source link

NoMethodError: undefined method `read_timeout=' for #<TCPSocket:(closed)> #9

Open jeremywadsack opened 9 years ago

jeremywadsack commented 9 years ago

Every time I try to close the connection (after an error state) I get this error.

Here is example code that reproduces the above error:

        ftps = DoubleBagFTPS.new
        begin
          ftps.debug_mode = true
          ftps.passive = true
          ftps.open_timeout = 1.0
          ftps.ftps_mode = DoubleBagFTPS::EXPLICIT
          ftps.connect 'ftp.secureftp-test.com'
          ftps.login 'test', 'test'
        rescue Net::FTPPermError => e
          puts e.class
          puts e.message
        rescue StandardError => e
          puts e.class
          puts e.message
        ensure
          ftps.close unless ftps.closed?
        end

This seems to be happening in the close method of Net::FTP:

NoMethodError: undefined method `read_timeout=' for #<TCPSocket:(closed)>
    from ~/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/ftp.rb:111:in `read_timeout='
    from ~/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/ftp.rb:960:in `ensure in close'
    from ~/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/ftp.rb:960:in `close'

I can't determine what DoubleBagFTPS is doing to cause this, but it doesn't happen if I switch to Net::FTP.

jeremywadsack commented 9 years ago

Ok, here's some more information. I get this when an error occurs during login. In this case a "certificate verify failed" error:

connect: ftp.secureftp-test.com, 21
get: 220 Microsoft FTP Service
put: AUTH TLS
get: 234 AUTH command ok. Expecting TLS Negotiation.
OpenSSL::SSL::SSLError
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

If I add the following before the call to close then it works.

          ftps.send :decorate_socket, ftps.instance_variable_get(:@sock)

The issue is that the failure happens when the socket attempts to connect. But decorate isn't called until after the socket is connected.

For some reason, #closed? returns false for a connection that has never opened.

jamonholmgren commented 8 years ago

I'm getting the same thing.

wconrad commented 8 years ago

I started to look at this a few months ago. Unfortunately, the public ftp site upon which this gem depends for it's tests is no more. If I get a chance I'll see if my ftpd or some other ruby ftp lib. can be used to create a new test suite. Ftpd uses this gem in its own tests, but not at runtime, so it ought to be ok, mostly, even if it is a little bit "close" of a relationship between the two. Either that, or we get lucky and find another public ftp server that has ssl support. On Sep 26, 2015 18:05, "Jamon Holmgren" notifications@github.com wrote:

I'm getting the same thing.

— Reply to this email directly or view it on GitHub https://github.com/bnix/double-bag-ftps/issues/9#issuecomment-143508824.

jamonholmgren commented 8 years ago

Thanks @wconrad! No rush.