Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:54:38+00:00 2026-05-27T19:54:38+00:00

I have been using open_uri to pull down an ftp path as a data

  • 0

I have been using open_uri to pull down an ftp path as a data source for some time, but suddenly found that I’m getting nearly continual “530 Sorry, the maximum number of allowed clients (95) are already connected.”

I am not sure if my code is faulty or if it is someone else who’s accessing the server and unfortunately there’s no way for me to really seemingly know for sure who’s at fault.

Essentially I am reading FTP URI’s with:

  def self.read_uri(uri)
    begin
      uri = open(uri).read
      uri == "Error" ? nil : uri
    rescue OpenURI::HTTPError
      nil
    end
  end

I’m guessing that I need to add some additional error handling code in here…
I want to be sure that I take every precaution to close down all connections so that my connections are not the problem in question, however I thought that open_uri + read would take this precaution vs using the Net::FTP methods.

The bottom line is I’ve got to be 100% sure that these connections are being closed and I don’t somehow have a bunch open connections laying around.

Can someone please advise as to correctly using read_uri to pull in ftp with a guarantee that it’s closing the connection? Or should I shift the logic over to Net::FTP which could yield more control over the situation if open_uri is not robust enough?

If I do need to use the Net::FTP methods instead, is there a read method that I should be familiar with vs pulling it down to a tmp location and then reading it (as I’d much prefer to keep it in a buffer vs the fs if possible)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:54:39+00:00Added an answer on May 27, 2026 at 7:54 pm

    I suspect you are not closing the handles. OpenURI’s docs start with this comment:

    It is possible to open http/https/ftp URL as usual like opening a file:
    
    open("http://www.ruby-lang.org/") {|f|
      f.each_line {|line| p line}
    }
    

    I looked at the source and the open_uri method does close the stream if you pass a block, so, tweaking the above example to fit your code:

    uri = ''
    open("http://www.ruby-lang.org/") {|f|
      uri = f.read
    }
    

    Should get you close to what you want.


    Here’s one way to handle exceptions:

    # The list of URLs to pass in to check if one times out or is refused.
    urls = %w[
      http://www.ruby-lang.org/
      http://www2.ruby-lang.org/
    ]
    
    # the method
    def self.read_uri(urls)
    
      content = ''
    
      open(urls.shift) { |f| content = f.read }
      content == "Error" ? nil : content
    
      rescue OpenURI::HTTPError
        retry if (urls.any?)
        nil
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using R to run simulations using time series data. I have been
I have been using the fantastic jQuery library for quite some time and have
I have been using an open source Java project and had to make some
I have been using emacs for some time now and am slowly getting the
I have been trying to do a fill using the open source Srecord Program.
I have been using Eclipse as an IDE for a short amount of time
I have been using Castle MonoRail for the last two years, but in a
I have been using ASP.NET for years, but I can never remember when using
I have been using Windows 7 for a while but have not had to
So I have been using a method to retrieve images from a website but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.