title: Ruby Net::FTP gettextfile not able to save files locally
body: <p>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:</p>
  
  <pre><code>#! /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
  </code></pre>
  
  <p>And here is the error I receive:</p>
  
  <pre><code>/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 &lt;main&gt;'
      from ftp_test.rb:33:in `each'
      from ftp_test.rb:33:in `block in &lt;main&gt;'
      from /Users/pierce/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/ftp.rb:116:in `open'
  </code></pre>
  
  <p>As suggested, here are the values I have for puts file and puts new_file.</p>
  
  <pre><code>file = -rwxr-xr-x    1 1130419  114727       9546 May 17 08:11 results_Wed. 16 May 2012.csv
  new_file = results_Wed0230May02012csv
  </code></pre>
  
  <p>Any suggestions on what to change in gettextfile or within my script to get the files saved correctly?</p>