Hello,


I have to check some folders on a ftp server, if they don't exist,
create it.


The main folder is:

project

the project has some folders, like 1,2,3,4,5,...

and each folder have 12 more folders, one for each month, and this
folders have many folders as days the current month have.


My code works, but I think is pretty slow and always, I'm getting an
EOFError: end of file reached after creating 50 folders, always.

How can I trace to find the error ?

thanks,

r.


  date=Date.new(2008,1,1)
   res.each{ |tuple|

   row_current+=1

     print "\n\n Row "+row_current.to_s+"/"+rows_to_fetch.to_s+" => "

     print  tuple['id'], ' ', tuple['name']

     project=ftp_acct+"/"+tuple['id']+"/"+date.year.to_s+"/"+'%02d' %
date.month+"/"+'%02d' % date.day
     project_month=ftp_acct+"/"+tuple['id']+"/"+date.year.to_s+"/"+'%02d'
% date.month
     project_year=ftp_acct+"/"+tuple['id']+"/"+date.year.to_s
     project_id=ftp_acct+"/"+tuple['id']


begin # project_id
  ftp.chdir(project_id)
  rescue Net::FTPPermError, NameError => boom
    ftp.mkdir("/"+project_id)

    print "Folder #{project_id} created"
end


begin # project_year
  ftp.chdir(project_year)
  rescue Net::FTPPermError, NameError => boom # it doesn't exist =>
create it
    ftp.mkdir("/"+project_year)
    print "Folder #{project_year} created"
end


for i in 1..12

  project_month=ftp_acct+"/"+tuple['id']+"/"+date.year.to_s+"/"+'%02d' %
i

begin # project_month
  ftp.chdir(project_month)
  rescue Net::FTPPermError, NameError => boom # it doesn't exist =>
create it
    ftp.mkdir("/"+project_month)
    print "Folder #{project_month} created"
end


if i == 12
  d=Date.new(date.year+1,1,1)-1
else
  d=Date.new(date.year.to_i,i+1,1)-1
end



puts "\n #{d.to_s}"


for days in 1..d.day

    project_day=ftp_acct+"/"+tuple['id']+"/"+date.year.to_s+"/"+'%02d' %
i+"/"+'%02d' % days

  begin # project_day
    ftp.chdir(project_day)
    rescue Net::FTPPermError, NameError => boom # it doesn't exist =>
create it
      ftp.mkdir("/"+project_day)
      print "Folder #{project_day} created"
  end

  print " \nFolder #{project_day} exists "


end # for days



end # for i in 1..12


    } # res.each{ |tuple|
-- 
Posted via http://www.ruby-forum.com/.