P
Peter Bailey
Hi,
I'm having to go to a website every day to pull files for editors at my
company. Unfortunately, the web site isn't maintained that well--they
keep old files. I have the power to, and I'd like to, delete any old
files that aren't stamped with today's date. Can someone help me? I'm
getting Net::FTPPermError errors when I run this.
I've modified the real names below to protect the innocent. But, the
filenames over there look like this:
lobbyreg-20071215-160004.xml
My code:
ftp = Net::FTP.open('ftpserver.zq.com')
ftp.login('zna','&n@c0ks')
ftp.chdir("/data/data/zna")
t = Time.now
t = t.strftime("%Y%m%d")
if Dir.glob("*.xml") then
xmlfiles = ftp.list('*.xml')
xmlfiles.each do |xmlfile|
if xmlfile.to_s.match(t.to_s) then
puts "Date matches!"
ftp.getbinaryfile(xmlfile.downcase)
else
puts "Dates don't match"
ftp.delete(xmlfile)
end
end
end
I'm having to go to a website every day to pull files for editors at my
company. Unfortunately, the web site isn't maintained that well--they
keep old files. I have the power to, and I'd like to, delete any old
files that aren't stamped with today's date. Can someone help me? I'm
getting Net::FTPPermError errors when I run this.
I've modified the real names below to protect the innocent. But, the
filenames over there look like this:
lobbyreg-20071215-160004.xml
My code:
ftp = Net::FTP.open('ftpserver.zq.com')
ftp.login('zna','&n@c0ks')
ftp.chdir("/data/data/zna")
t = Time.now
t = t.strftime("%Y%m%d")
if Dir.glob("*.xml") then
xmlfiles = ftp.list('*.xml')
xmlfiles.each do |xmlfile|
if xmlfile.to_s.match(t.to_s) then
puts "Date matches!"
ftp.getbinaryfile(xmlfile.downcase)
else
puts "Dates don't match"
ftp.delete(xmlfile)
end
end
end