title: update to database from local disk doesnt happen using pymysql
body: <p>I have a scenario where I am downloading few .csv files from sftp server to my local linux server using python script(downloadsftp.py), once the files are downloaded I rename those csv files and trigger (updatedb.py), this whole thing cron jobs has been set up.</p>
  
  <p>What I see is the files which I download from the SFTP server is updated but when the cron job runs automatically at specified time it does not push updated files to database but the old or previous files.
  file permissions are chmod 777 for all files that are downloaded that is achieved via another cron job.</p>
  
  <p>Here are my scripts :</p>
  
  <p>downloadsftp.py</p>
  
  <pre><code>filelist = server.listdir()
  for filename in filelist:
      filedate = re.search(".*\.csv$", filename)
      if filedate:
          print (filename)
          server.get("/sftpfolder/" + filename, "/opt/currentdata/" + filename)
          print("latest files downloaded to /opt/currentdata now proceeeding with creating backup")
          server.get("/sftpfolder/" + filename, "/opt/backupdata/" + filename)
          print("backup files created in /opt/backupdata")
          server.remove("/sftpfolder/" + filename)
          print ("cleaning files from FTP server")
  
  print ("SFTP process completed closing FTP connection")
  server.close()
  
  print ("Bye Bye SFTP")
  
  print ("Renaming files for updating database")
  print(" ")
  
  dir= "/opt/currentdata"
  
  for newname in os.listdir(dir):
           if(newname.split('.')[0]=='CAS1' and "J" in newname):
                  print newname,'BASD.csv'
                  shutil.move(newname, "BASD.csv")
  
  for newname in os.listdir(dir):
           if(newname.split('.')[0]=='LST' and "N" in newname):
                  print newname,'CVGH.csv'
                  shutil.move(newname, "CVGH.csv")
  </code></pre>
  
  <p>Dbupdate.py</p>
  
  <pre><code>def csv_to_mysql(load_sql, host, user, password):
      '''
      This function load a csv file to MySQL table according to
      the load_sql statement.
      '''
      try:
          con = pymysql.connect(host=host,
                                  user=user,
                                  password=password,
                                  autocommit=True,
                                  local_infile=1)
          print('Connected to DB: {}'.format(host))
          # Create cursor and execute Load SQL
          cursor = con.cursor()
          cursor.execute("truncate table mdb.data1;")
          cursor.execute("truncate table mdb.data2;")
          print("truncated old values from database...updating current values")
          cursor.execute(load_sql)
          cursor.execute(load_sql1)
          print('Succuessfully updated the table from currentdata dir')
          con.close()
  
      except Exception as e:
          print('Error: {}'.format(str(e)))
          sys.exit(1)
  
  # Execution Example
  load_sql = """ LOAD DATA LOCAL INFILE '/opt/currentdata/BASD.csv' INTO TABLE mdb.data1\
   FIELDS TERMINATED BY ';' ENCLOSED BY '"' IGNORE 1 LINES; """
  
  load_sql1 = """ LOAD DATA LOCAL INFILE '/opt/currentdata/CVGH.csv' INTO TABLE mdb.data2\
   FIELDS TERMINATED BY ';' ENCLOSED BY '"' IGNORE 1 LINES; """
  
  host = 'xxx'
  user = 'dd'
  password = 'ww'
  
  csv_to_mysql(load_sql, host, user, password)
  </code></pre>
  
  <p>Cron jobs :</p>
  
  <pre><code>30 21 * * * cd /opt/currentdata/ &amp;&amp; python /opt/currentdata/downloadsftp.py &gt;&gt; /opt/scriptlogs/sftp.log 2&gt;&amp;1
  33 21 * * * cd /opt/currentdata/ &amp;&amp; python /opt/currentdata/dbupdate.py &gt;&gt; /opt/scriptlogs/db1all.log 2&gt;&amp;1
  </code></pre>
  
  <p>I have no idea why the updated files are not pushed in database but the old files can somebody help here to understand if there is a problem with cron or downloading and moving the file in server because when I run the dbupdate.py script manually from the directory it updates correctly.</p>