looping

T

Tim Wolak

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
 
T

Tim Wolak

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
 
T

Tim Wolak

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top