T
Tim Wolak
Morning all,
I am downloading a file that gets loaded sometime after 10PM and we
never know what time it will be put on the server. I have my code look
for the file and if it does not match my test then sleep for 1800ms and
then check again. I have the code getting the file I need just fine but
when I add the sleep, it just sleeps straight away when I know the
correct file is there. Can you guys have a look and let me know where
I'm going wrong?
Also if there is a better way to just look at the FTP directory and see
if the file is there I am open to any ideas.
Thanks in advance,
Tim
require 'net/ftp'
class Download
ftp = Net::FTP.new('ftp.site.com')
ftp.login(user="uname", 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 < 0)
@procFile = @curdate
end
@lastProc = @last
@list.scan(/\d{8}/) do | @scan |
if (@scan == @procFile && @list =~ /Balances\d{8}/)
Dir.chdir("/tmp")
ftp.gettextfile(@list, localfile = File.basename(@list))
else (@list !~ /Balances#{@procFile}.txt/)
sleep(1800)
end
end
end
end
I am downloading a file that gets loaded sometime after 10PM and we
never know what time it will be put on the server. I have my code look
for the file and if it does not match my test then sleep for 1800ms and
then check again. I have the code getting the file I need just fine but
when I add the sleep, it just sleeps straight away when I know the
correct file is there. Can you guys have a look and let me know where
I'm going wrong?
Also if there is a better way to just look at the FTP directory and see
if the file is there I am open to any ideas.
Thanks in advance,
Tim
require 'net/ftp'
class Download
ftp = Net::FTP.new('ftp.site.com')
ftp.login(user="uname", 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 < 0)
@procFile = @curdate
end
@lastProc = @last
@list.scan(/\d{8}/) do | @scan |
if (@scan == @procFile && @list =~ /Balances\d{8}/)
Dir.chdir("/tmp")
ftp.gettextfile(@list, localfile = File.basename(@list))
else (@list !~ /Balances#{@procFile}.txt/)
sleep(1800)
end
end
end
end