Project

niftp

0.01
No commit activity in last 3 years
No release in over 3 years
NiFTP makes Ruby's decidedly un-nifty Net::FTP library easier to use.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 4.7
~> 0.14
>= 0

Runtime

>= 0.5
>= 2.0
 Project Readme

NiFTP

Only supports Ruby 2.0.0+ A Ruby gem, makes Ruby's decidedly un-nifty Net::FTP library easier to use. It abstracts away the FTP plumbing, such as establishing and closing connections. Options include retrying your commands on flakey FTP servers, and forced timeouts. FTP Secure (FTPS) is also supported.

Code Climate Build Status

Usage

# Without NiFTP:
begin
  client = Net::FTP.new("localhost")
  client.list
ensure
  client.try(:close)
end

# With NiFTP:
ftp("localhost") { |client| client.list }

# A more concrete example:

# Mixin the +NiFTP+ module, which provides the +ftp+ method.
require 'niftp'
class SomeObject
  include NiFTP

  def ftps_options
    {
      username: "",
      password: "",
      ftps: true,
      ssl_context_params: {
        verify_mode: OpenSSL::SSL::VERIFY_NONE
      }
    }
  end

  def ftp_stuff
    ftp("ftp.appareldownload.com", ftps_options) do |client|
      files = client.list('n*')
      # ...
      file = client.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
      # ...
    end
  end
end

Options

  • username: The user name, if required by the host (default: "").
  • password: The password, if required by the host (default: "").
  • port: The port for the host (default: 21).
  • tries: The number of times to try the given FTP commands upon any exception, before raising the exception (Default: 2, meaning it will retry once upon any exception).
  • sleep: The number of seconds to sleep in between tries (default: 1).
  • on: An array of errors to limit when the code block is retried (default: StandardError). See the retryable gem for usage details
  • matching: An exception message regex to limit when the code block is retried (default: /.*/). See the retryable gem for usage details
  • timeout: The number of seconds to wait before timing out authentication (default: 30). Use 0 to disable the authentication timeout.
  • passive: Set to false to prevent a connection in passive mode (default: true).
  • ftps: Set to true if connecting to a FTP Secure server (default: false).
  • ftps_mode: Set to one of the following: DoubleBagFTPS::EXPLICIT or DoubleBagFTPS::IMPLICIT (default: DoubleBagFTPS::IMPLICIT).
  • ssl_context_params: See the DoubleBagFTPS for options. (default: { }).

Caveats

Setting the :tries option to 0 will raise a runtime error, otherwise the codeblock would never execute.

Testing

Tests are written using minitest-spec and Mocha.