Git Product home page Git Product logo

double-bag-ftps's Introduction

DoubleBagFTPS

DoubleBagFTPS extends the core Net::FTP class to provide implicit and explicit FTPS support.

Install

$ [sudo] gem install double-bag-ftps

Note: Your Ruby installation must have OpenSSL support.

Usage

require 'double_bag_ftps'

Example 1:

# Connect to a host using explicit FTPS and do not verify the host's cert
ftps = DoubleBagFTPS.new
ftps.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OpenSSL::SSL::VERIFY_NONE)
ftps.connect('some host')
ftps.login('usr', 'passwd')

Example 2:

DoubleBagFTPS.open('host', 'usr', 'passwd', nil, DoubleBagFTPS::IMPLICIT) do |ftps|
  ...
end

Interface

# Constants used for setting FTPS mode
DoubleBagFTPS::EXPLICIT
DoubleBagFTPS::IMPLICIT

DoubleBagFTPS.new(host = nil, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {})
DoubleBagFTPS.open(host, user = nil, passwd = nil, acct = nil, ftps_mode = EXPLICIT, ssl_context_params = {})

# Returns an OpenSSL::SSL::SSLContext using params to set set the corresponding SSLContext attributes.
DoubleBagFTPS.create_ssl_context(params = {})

# Set the FTPS mode to implicit (DoubleBagFTPS::IMPLICIT) or explicit (DoubleBagFTPS::EXPLICIT).
# The default FTPS mode is explicit. 
ftps_mode=(ftps_mode)

# Same as Net::FTP.connect, but will use port 990 when using implicit FTPS and a port is not specified.
connect(host, port = ftps_implicit? ? IMPLICIT_PORT : FTP_PORT)

# Same as Net::FTP.login, but with optional auth param to control the value that is sent with the AUTH command.
login(user = 'anonymous', passwd = nil, acct = nil, auth = 'TLS')

ftps_explicit?
ftps_implicit?

More Information

License

Copyright © 2011, Bryan Nix. DoubleBagFTPS is released under the MIT license. See LICENSE file for details.

double-bag-ftps's People

Contributors

bnix avatar wconrad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

double-bag-ftps's Issues

Incompatibility with Ruby 2.4.x

Ruby 2.4.x introduces TLS support for net/ftp - https://github.com/ruby/ruby/blob/ruby_2_4/lib/net/ftp.rb. The changes in the class functions caused issues with double-bag-ftps extended function.

A couple notable differences:

  • net/ftp only supports explicit FTPS. It doesn't support implicit FTPS
  • net/ftp connect() does 'AUTH TLS' if ssl option is set (conflicts with double-bag-ftps login() function)

Are there any plans to support Ruby 2.4.x ?

Thanks.

RubyGem release 0.1.3

I have been watching an issue that was recently merged into master, but the gem wasn't released in rubygems.org. Any plans to bump the version on RubyGems ?

Handle private address being returned by a server

One server that I'm trying to get a file is returning a private address with passive mode in a Explicit tls connection, I've made a simple addition to solve the issue if the address is private.

DoubleBagFTPS timeout in ruby

I'm trying to use "double-bag-ftps" gem to connect local machine to ftp server but I met a issue => the code shown below

p 'before ftp'
ftps = DoubleBagFTPS.new
ftps.passive = true
ftps.ftps_mode = DoubleBagFTPS::EXPLICIT
ftps.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode =>    OpenSSL::SSL::VERIFY_NONE)
ftps.connect('xx.xx.xx.xx', '990')
ftps.login('user', 'password')

p 'after ftp'
p 'before filename'
puts ftps.nlst.first
p 'after filename'

the console output:

"before ftp"
DoubleBagFTPS:0x000000032ca378 @ftps_mode=:explicit, @ssl_context=#<OpenSSL::SSL::SSLContext:0x000000032ca030 @cert=nil, @key=nil, @client_ca=nil, @ca_file=nil, @ca_path=nil, @timeout=nil, @verify_mode=0, @verify_depth=nil, @renegotiation_cb=nil, @verify_callback=nil, @options=-2147482625, @cert_store=nil, @extra_chain_cert=nil, @client_cert_cb=nil, @tmp_dh_callback=nil, @session_id_context=nil, @session_get_cb=nil, @session_new_cb=nil, @session_remove_cb=nil, @servername_cb=nil, @npn_protocols=nil, @npn_select_cb=nil>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x000000032ca0a8>, @binary=true, @passive=true, @debug_mode=false, @resume=false, @sock=#<OpenSSL::SSL::SSLSocket:0x000000032c97c0 @io=#<TCPSocket:fd 7>, @context=#<OpenSSL::SSL::SSLContext:0x000000032ca030 @cert=nil, @key=nil, @client_ca=nil, @ca_file=nil, @ca_path=nil, @timeout=nil, @verify_mode=0, @verify_depth=nil, @renegotiation_cb=nil, @verify_callback=nil, @options=-2147482625, @cert_store=nil, @extra_chain_cert=nil, @client_cert_cb=nil, @tmp_dh_callback=nil, @session_id_context=nil, @session_get_cb=nil, @session_new_cb=nil, @session_remove_cb=nil, @servername_cb=nil, @npn_protocols=nil, @npn_select_cb=nil>, @sync_close=true, @hostname=nil, @eof=false, @rbuffer="", @sync=true, @callback_state=nil, @wbuffer="">, @logged_in=true, @open_timeout=nil, @read_timeout=60, @hostname="xx.xx.xx.xx", @last_response="200 PROT now Private.\n", @last_response_code="200", @ssl_session=#<OpenSSL::SSL::Session:0x000000032c9720>, @welcome="230 Login successful.\n">
"after ftp"
"before filename"
/brabra/lib/double_bag_ftps.rb:83:in `initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT)

login to ftps server works fine but it will stuck at "fetching first file name" in ftp server and result is timeout... No idea about this and very thanks.

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

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.

active mode data transfers hang

connect: 192.168.1.1, 990
get: Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 0 (0x0)
        Signature Algorithm: md5WithRSAEncryption
        Issuer: C=US, CN=ftp.XXXXXXXX.com, L=San Francisco, OU=MIS Department, O=XXXXXXXX, ST=CA/[email protected]
        Validity
            Not Before: Aug 20 17:55:00 2008 GMT
            Not After : Aug 20 17:55:00 2020 GMT
        Subject: C=US, CN=ftp.XXXXXXXX.com, L=San Francisco, OU=MIS Department, O=XXXXXXXX, ST=CA/[email protected]
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
                Modulus:
                    00:db:8d:41:4b:8e:09:ee:58:a6:d4:53:6d:e1:17:
...
                    60:43:27:7a:17:6e:10:46:1f
                Exponent: 65537 (0x10001)
    Signature Algorithm: md5WithRSAEncryption
        3f:e6:20:2a:f2:be:c1:cb:6c:63:ab:2b:b3:14:c2:04:9f:87:
...
                    60:43:27:7a:17:6e:10:46:1f
get: 220 GlobalSCAPE Secure FTP Server
put: USER user
get: 331 Password required for user.
put: PASS ********
get: 230 Login OK. Proceed.
put: TYPE I
get: 200 Type set to I.
put: PBSZ 0
get: 200 PBSZ Command OK. Protection buffer size set to 0.
put: PROT P
get: 200 PROT Command OK. Using Private data connection
put: TYPE A
get: 200 Type set to A.
put: PORT 192,168,1,150,4,48
get: 200 Command okay.
put: LIST
get: 150 Opening ASCII mode data connection for file list.
put: TYPE I

The script halted at the line "ftps.list" (see below) until I break it.

Please advise. Thank you.

Here is my script

require 'bundler/setup'
Bundler.require

host = '192.168.1.1'
user = 'user'
passwd = 'password'

ftps = DoubleBagFTPS.new
ftps.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OpenSSL::SSL::VERIFY_NONE, :ssl_version  => "SSLv3")
ftps.debug_mode = true
ftps.ftps_mode = DoubleBagFTPS::IMPLICIT
ftps.connect(host)
ftps.login(user, passwd)
ftps.welcome
ftps.list
ftps.close

Possible incompatibility with ruby 2.1.1

I am trying to use your gem. This is my code:

ftp = DoubleBagFTPS.new
ftp.ftps_mode = DoubleBagFTPS::EXPLICIT
ftp.passive = true
ftp.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OpenSSL::SSL::VERIFY_NONE)
ftps.connect('ftpssl.autoims.com')
ftps.login('ASEV', 'password')
puts ftps.nlst.first

This is the output that I get:

Net::FTPPermError: 501 Syntax error in 'PORT 10,194,79,186,226,4'

    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:327:in `getresp'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:339:in `voidresp'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:362:in `block in voidcmd'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:360:in `voidcmd'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:376:in `sendport'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:387:in `makeport'
    from /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/double-bag-ftps-0.1.2/lib/double_bag_ftps.rb:111:in `transfercmd'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:515:in `block (2 levels) in retrlines'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:199:in `with_binary'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:513:in `block in retrlines'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:512:in `retrlines'
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/ftp.rb:745:in `nlst'
    from (irb):29
    from /home/ubuntu/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'

Can you give any pointers if I am doing something wrong? Or is the gem possibly not compatible with ruby 2.1.1?

0.1.2 socket re-use causes JRuby to fail when attempting to log in

Using jruby.1.7.16 and double-bag-ftps.0.1.2 on Windows 7.

Jruby does not have support for openssl.session as described in this issue:
GitHub - jruby issue 197

And also in this issue:
GitHub - mechanize issue 207

The following code will result in "NameError: uninitialized constant OpenSSL::SSL::Session from org/jruby/RubyModule.java:2723:in 'const_missing'

require 'double_bag_ftps'

connection = DoubleBagFTPS.new
connection.passive = true
connection.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OPENSSL::SSL::VERIFY_NONE)
connection.connect('ftps_server')
connection.login('user','pass')

Reverting to version 0.1.1 is my current work-around. I'm hoping that the ability to disable socket reuse will be included in version 0.1.3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.