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 8133417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:36:02+00:00 2026-06-06T09:36:02+00:00

I am trying to retrieve files (.csv) from an ftp site and save them

  • 0

I am trying to retrieve files (.csv) from an ftp site and save them all locally in the same folder. My code looks like this:

#! /usr/bin/ruby

require 'logger'
require 'fileutils'
require 'net/ftp'
require 'rubygems'
require 'mysql2'
require 'roo'
require 'date'

# logging setup
log = Logger.new("/path_to_logs/ftp_log.log", 10, 1024000)
log.level = Logger::INFO

export_ftp_path = '/Receive/results/'
export_work_path ='/Users/pierce/results_exports/'

Net::FTP.open('host', 'username', 'password') do |ftp|
    log.info("Logged into FTP")
    ftp.passive = true
    ftp.chdir("#{export_ftp_path}")
      ftp.list.each do |file|
        log.info("Found file #{file}")
        new_file = file[56..115]  #take part of the file name and remove spaces and periods
        new_file = new_file.gsub(/[.]+/, "") 
        new_file = new_file.gsub(/\s/, "0") 
        ftp.gettextfile(file,"#{new_file}")
        log.info("Downloaded file #{new_file}")
      end
end

And here is the error I receive:

/Users/pierce/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/ftp.rb:560:in `initialize': No such file or directory -  (Errno::ENOENT)
    from /Users/pierce/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/ftp.rb:560:in `open'
    from /Users/pierce/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/ftp.rb:560:in `gettextfile'
    from ftp_test.rb:44:in `block (2 levels) in <main>'
    from ftp_test.rb:33:in `each'
    from ftp_test.rb:33:in `block in <main>'
    from /Users/pierce/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/ftp.rb:116:in `open'

As suggested, here are the values I have for puts file and puts new_file.

file = -rwxr-xr-x    1 1130419  114727       9546 May 17 08:11 results_Wed. 16 May 2012.csv
new_file = results_Wed0230May02012csv

Any suggestions on what to change in gettextfile or within my script to get the files saved correctly?

  • 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-06-06T09:36:04+00:00Added an answer on June 6, 2026 at 9:36 am

    You should use nlst instead of list when you just need a list of files in a directory. The output of list needs to be properly parsed otherwise.

    When you request the file it has to be the original filename, including all spaces. When you save the file it can be anything you want (including spaces or not). The error was because you were requesting the wrong file. Use nlst in your case instead. It will make it much easier (no conversion or parsing needed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve file details from files in the Program Files folder.
I'm trying to walk a directory, retrieve all files within that directory ending with
I am trying to retrieve DataTable from .xls file. Below are my code: OleDbConnection
I am trying retrieve user name from the code through graph api, the below
I'm trying to retrieve images from a folder using glob() and i want it
I am trying to retrieve all the files in all the folders I have
I'm trying to retrieve files from sharepoint via SSRS and an XML Datasource. This
I'm trying to retrieve a list of documents from a folder named myfolder in
I am trying to create a program to copy all the files from one
I am trying to retrieve list of files from a server with the windows

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.