Skip to content

Instantly share code, notes, and snippets.

@albertoperdomo
Created January 28, 2010 16:13
Show Gist options
  • Save albertoperdomo/288874 to your computer and use it in GitHub Desktop.
Save albertoperdomo/288874 to your computer and use it in GitHub Desktop.
# This works on Ruby 1.8.7 but doesn't work on Ruby 1.8.6 (See backtrace further down)
require 'net/ftp'
require 'fileutils'
URL = 'XXX.XXX.XXX.XXX'
username = 'XXXXXXXXXX'
passwd = "XXXXXXXXX"
directory = '/out/archive/'
Net::FTP.open(URL) do |ftp|
ftp.debug_mode = true
#ftp.passive = true
#ftp.binary = false
ftp.login(username,passwd)
ftp.chdir(directory)
ftp.list do |line|
filename = line.split(' ').last
localfile = filename
puts "get #{filename} => #{line}"
ftp.get(filename, localfile)
end
ftp.close
puts "Finished successfuly"
end
# Works as expected on Ruby 1.8.7
#
# Returns following error on Ruby 1.8.6:
#
# /usr/local/lib/ruby/1.8/net/ftp.rb:211:in `readline': end of file reached (EOFError)
# from /usr/local/lib/ruby/1.8/net/ftp.rb:211:in `getline'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:221:in `getmultiline'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:235:in `getresp'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:251:in `voidresp'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:274:in `voidcmd'
# from /usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:272:in `voidcmd'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:287:in `sendport'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:295:in `makeport'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:326:in `transfercmd'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:420:in `retrlines'
# from /usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:418:in `retrlines'
# from /usr/local/lib/ruby/1.8/net/ftp.rb:624:in `list'
# from ftp.rb:19
# from /usr/local/lib/ruby/1.8/net/ftp.rb:115:in `open'
# from ftp.rb:13
# This works both with Ruby 1.8.6 and 1.8.7
require 'net/ftp'
require 'fileutils'
URL = 'XXX.XXX.XXX.XXX'
username = 'XXXXXXXXXX'
passwd = "XXXXXXXXX"
directory = '/out/archive/'
Net::FTP.open(URL) do |ftp|
ftp.debug_mode = true
ftp.passive = true
#ftp.binary = false
ftp.login(username,passwd)
ftp.chdir(directory)
list = ftp.list
for line in list
filename = line.split(' ').last
localfile = filename
puts "get #{filename} => #{line}"
ftp.get(filename, localfile)
end
ftp.close
puts "Finished successfuly"
end
@stanBienaives
Copy link

You just saved my afternoon thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment