title: Get last modifed csv files from ftp server using python
body: <p>I am trying to get yesterdays csv files generated from ftp server from multiple folders.
  I can connect to ftp and get all csv files from a particular folder but not able to iterate the for loop to get all the files from sub folders.</p>
  <pre><code>FTP folder structure
  /home/lan1/city/hyd/2022-03-14/hyd.csv
  /home/lan1/city/knr/2022-03-14/knr.csv
  /home/lan1/city/wgl/2022-03-14/wgl.csv
  
  My code :
  
  ftp = ftplib.FTP('192.00.000.00', 'lan1', 'G01d')
  files = ftp.dir('/')
  ftp.cwd('/home/lan1/city/')
  PATH = '/home/lan1/city/*'
  filematch = &quot;*.csv&quot;
  target_dir = '/var/www/CSV'
  
  import os
  from glob import glob
  for root, subdirectories, files in os.walk (PATH):
      for filename in ftp.nlst(filematch):
          target_file_name = os.path.join(target_dir,os.path.basename(filename))
          with open(target_file_name,'wb') as fhandle:
           ftp.retrbinary('RETR %s' %filename, fhandle.write)
  </code></pre>
  <p>I am able to get csv files from /home/lan1/city if I put any csv file on it  but I need to get all the csv files from yesterday.</p>