Is there an easy to use FTP library for Ruby?

Is there a high-level Ruby library for interacting with an FTP server?

Instead of Net :: HTTP, I can use HTTParty, Curb, Rest Client or Typhoeus, which makes everything simpler, but I can not find similar solutions to replace / improve Net :: FTP.

In particular, I am looking for:

  • minimum lines to connect to the server. For example, the login must be explicitly specified using Net :: FTP
  • the ability to repeat all the entries in one folder or using glob or just recursively.
  • the ability to receive all possible information, such as record type, size, time without manually analyzing the returned rows.
+4
source share
2 answers

Ruby's built-in Open-URI will handle FTP.

In the Open-URI docs:

OpenURI is an easy-to-use wrapper for net / http, net / https and net / ftp.

It looks like it freezes when it fetches the Ruby source, but should return in a minute or two.

require 'open-uri' open('ftp://ftp.ruby-lang.org//pub/ruby/ruby-1.9.2-p136.tar.bz2') do |fi| File.open('ruby-1.9.2-p136.tar.bz2', 'wb') do |fo| fo.puts fi.read end end 

Or, Net :: FTP is easy to use with much more functionality:

 require 'net/ftp' Net::FTP.open('ftp.ruby-lang.org') do |ftp| ftp.login ftp.chdir('/pub/ruby') puts ftp.list('ruby-1.9.2*') puts ftp.nlst() ruby_file = 'ruby-1.9.2-p136.tar.bz2' ftp.getbinaryfile(ruby_file, ruby_file, 1024) end 
+5
source

Have you tried EventMachine? https://github.com/schleyfox/em-ftp-client

+4
source

Source: https://habr.com/ru/post/1339996/


All Articles