# Downloading specific file

**URL:** <https://www.ruby-forum.com/t/downloading-specific-file/226009>\
**Category:** Ruby\
**Created:** [June 12, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/downloading-specific-file/226009 "2008-06-12T16:07:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [June 12, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/downloading-specific-file/226009/1 "2008-06-12T16:07:44Z")

</div>

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](http://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
