# Automatic IOT data collection by FTP

**URL:** <https://forum.inductiveautomation.com/t/automatic-iot-data-collection-by-ftp/16845>\
**Category:** General Discussion\
**Created:** [February 2, 2018, 7:04am UTC](https://forum.inductiveautomation.com/t/automatic-iot-data-collection-by-ftp/16845 "2018-02-02T07:04:50Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 5, 2018, 1:08pm UTC](https://forum.inductiveautomation.com/t/automatic-iot-data-collection-by-ftp/16845/4 "2018-02-05T13:08:54Z")

</div>

something like this would put a csv file into a db table. [pymsql](https://pypi.python.org/pypi/PyMySQL) is pure python.

```auto
# csv to MySQL

import os, shutil, csv, pymysql

inputPath = '/path/to/input/folder/'
archivePath = '/path/to/archive/folder'

# get list of files
files = os.listdir(inputPath)

if len(files) > 0:
  # set MySQL connection
  connection = pymysql.connect(host='host.com', user='', password='', db='', cursorclass=pymysql.cursors.DictCursor)

  # set query  
  query = 'INSERT INTO table VALUES(%s, %s, %s, %s, %s)'

  # loop through files
  for file in files:
    inputFile = inputPath + file
	
	# open csv file
    dataIn = csv.reader(inputFile, delimiter =',' quotechar ='"')
	
	# write to db
    with connection.cursor() as cursor:
        for line in dataIn:
            cursor.execute(sql, (line[0]))
  
  # commit and close the MySQL connection
  connection.commit()
  connection.close()

  # move the files to the archive folder
  for file in files:
    shutil.move(inputPath + file, archivePath + file)

```

As far as putting it into the Ignition historian without using Ignition, I can’t help you there, because I don’t use the historian. None of the applications I have here have any need of it.

---

_[View the full topic](https://forum.inductiveautomation.com/t/automatic-iot-data-collection-by-ftp/16845)._
