Looping

Can someone explain why my code is stopping after looking at the first
file? There are at least 20 files in this directory and it stops after
checking just one.

require ‘net/ftp’

class Download
ftp = Net::FTP.new(‘ftp.site.com’)
ftp.login(user=“user”, passwd=“123”)
file = ftp.nlst
file.each do | list |
last = “20080609”
curdate = Time.now.localtime.strftime(“%Y%m%d”)
yesterday = Time.now - 86400
prevday = yesterday.strftime(“%Y%m%d”)
t = Time.now
hour = t.hour
if(hour >= 0)
procFile = prevday
elsif(hour < 23)
procFile = curdate
end
#procFile = 20080613
lastProc = last
list.scan(/\d{8}/) do | t |
p [t, procFile, list]
if(t == procFile && list =~ /FutBal\d{8}.txt/)
Dir.chdir(“/tmp”)
ftp.gettextfile(list, localfile = File.basename(list))
exit
elsif(t != procFile && list !~ /FutBal#{procFile}.txt/)
sleep(1800)
end
end
end
end

Tim W. wrote:

Can someone explain why my code is stopping after looking at the first
file? There are at least 20 files in this directory and it stops after
checking just one.

     if(t == procFile && list =~ /FutBal\d{8}.txt/)
       Dir.chdir("/tmp")
       ftp.gettextfile(list, localfile = File.basename(list))
       exit

Perhaps you didn’t mean to call “exit?”

-Dana

     if(t == procFile && list =~ /FutBal\d{8}.txt/)
       Dir.chdir("/tmp")
       ftp.gettextfile(list, localfile = File.basename(list))
       exit

Perhaps you didn’t mean to call “exit?”

-Dana

Even if I take that out it still only reads one file in and skips right
to the sleep not looking at the other files.

Thanks,
Tim

Is there a naming conflict with the variable “t?” Try changing

list.scan(/\d{8}/) do |t|

to use a different variable.

-Dana

Thanks Dana,

There is not a conflict, when print out the variables used I can see it
reading the first line and then that’s all it reads. If write in next
instead of exit it will loop through all the lines. If the test fails
it should hit the sleep instruction which it won’t do.

Thanks,
Tim

Tim W. wrote:

Even if I take that out it still only reads one file in and skips right
to the sleep not looking at the other files.

Thanks,
Tim

Is there a naming conflict with the variable “t?” Try changing

list.scan(/\d{8}/) do |t|

to use a different variable.

-Dana