diff --git a/csvLoader/CsvLoader.py b/CsvLoader.py similarity index 100% rename from csvLoader/CsvLoader.py rename to CsvLoader.py diff --git a/ftpReceiver/FtpCsvReceiver.py b/FtpCsvReceiver.py similarity index 94% rename from ftpReceiver/FtpCsvReceiver.py rename to FtpCsvReceiver.py index 73ccd43..f5ff7cc 100755 --- a/ftpReceiver/FtpCsvReceiver.py +++ b/FtpCsvReceiver.py @@ -35,7 +35,7 @@ class DummySha256Authorizer(DummyAuthorizer): # Crea un cursore cur = conn.cursor() - cur.execute(f'SELECT ftpuser, hash, virtpath, perm FROM {cfg.dbschema}.{cfg.dbtable} WHERE deleted_at IS NULL') + cur.execute(f'SELECT ftpuser, hash, virtpath, perm FROM {cfg.dbschema}.{cfg.dbusertable} WHERE deleted_at IS NULL') for ftpuser, hash, virtpath, perm in cur.fetchall(): self.add_user(ftpuser, hash, virtpath, perm) @@ -136,7 +136,7 @@ class ASEHandler(FTPHandler): # Crea un cursore cur = conn.cursor() - cur.execute(f"INSERT INTO {cfg.dbschema}.{cfg.dbtable} (ftpuser, hash, virtpath, perm) VALUES ('{user}', '{hash}', '{cfg.virtpath + user}', '{cfg.defperm}')") + cur.execute(f"INSERT INTO {cfg.dbschema}.{cfg.dbusertable} (ftpuser, hash, virtpath, perm) VALUES ('{user}', '{hash}', '{cfg.virtpath + user}', '{cfg.defperm}')") conn.commit() conn.close() logging.info("User {} created.".format(user)) @@ -159,7 +159,7 @@ class ASEHandler(FTPHandler): # Crea un cursore cur = conn.cursor() - cur.execute(f"UPDATE {cfg.dbschema}.{cfg.dbtable} SET deleted_at = now() WHERE ftpuser = '{user}'") + cur.execute(f"UPDATE {cfg.dbschema}.{cfg.dbusertable} SET deleted_at = now() WHERE ftpuser = '{user}'") conn.commit() conn.close() @@ -183,10 +183,10 @@ class ASEHandler(FTPHandler): # Crea un cursore cur = conn.cursor() - cur.execute(f"UPDATE {cfg.dbschema}.{cfg.dbtable} SET deleted_at = null WHERE ftpuser = '{user}'") + cur.execute(f"UPDATE {cfg.dbschema}.{cfg.dbusertable} SET deleted_at = null WHERE ftpuser = '{user}'") conn.commit() - cur.execute(f"SELECT ftpuser, hash, virtpath, perm FROM {cfg.dbschema}.{cfg.dbtable} WHERE ftpuser = '{user}'") + cur.execute(f"SELECT ftpuser, hash, virtpath, perm FROM {cfg.dbschema}.{cfg.dbusertable} WHERE ftpuser = '{user}'") ftpuser, hash, virtpath, perm = cur.fetchone() self.authorizer.add_user(ftpuser, hash, virtpath, perm) @@ -217,7 +217,7 @@ class ASEHandler(FTPHandler): # Crea un cursore cur = conn.cursor() self.push("214-The following virtual users are defined:\r\n") - cur.execute(f'SELECT ftpuser, perm FROM {cfg.dbschema}.{cfg.dbtable} WHERE deleted_at IS NULL ') + cur.execute(f'SELECT ftpuser, perm FROM {cfg.dbschema}.{cfg.dbusertable} WHERE deleted_at IS NULL ') [users_list.append(f'Username: {ftpuser}\tPerms: {perm}\r\n') for ftpuser, perm in cur.fetchall()] self.push(''.join(users_list)) self.respond("214 LSTU SITE command successful.") diff --git a/csvLoader/transform_file.py b/csvLoader/transform_file.py deleted file mode 100644 index fa23794..0000000 --- a/csvLoader/transform_file.py +++ /dev/null @@ -1,102 +0,0 @@ -import json -import psycopg2 -from sqlalchemy import create_engine, text - -# Configura la connessione al database PostgreSQL -engine = create_engine('postgresql://asepg:batt1l0@10.211.114.101:5432/asedb') - -def write_db(engine, records): - with engine.connect() as conn: - conn.execute(text(""" - INSERT INTO dataraw (nome_unit, tipo_centralina, nome_tool, tipo_tool, ip_centralina, ip_gateway, event_timestamp, battery_level, temperature, nodes_jsonb) - VALUES - """ + ",".join([ - f"(:{i}_nome_unit, :{i}_tipo_centralina, :{i}_nome_tool, :{i}_tipo_tool, :{i}_ip_centralina, :{i}_ip_gateway, :{i}_event_timestamp, :{i}_battery_level, :{i}_temperature, :{i}_nodes_jsonb)" - for i in range(len(records)) - ]) + """ - ON CONFLICT ON CONSTRAINT dataraw_unique - DO UPDATE SET - tipo_centralina = EXCLUDED.tipo_centralina, - tipo_tool = EXCLUDED.tipo_tool, - ip_centralina = EXCLUDED.ip_centralina, - ip_gateway = EXCLUDED.ip_gateway, - battery_level = EXCLUDED.battery_level, - temperature = EXCLUDED.temperature, - nodes_jsonb = EXCLUDED.nodes_jsonb; - """), {f"{i}_{key}": value for i, record in enumerate(records) for key, value in record.items()}) - - conn.commit() - - -# Leggi il file intero e separa l'intestazione dal resto dei dati -with open('DT0029_20241106044856.csv', 'r') as file: - lines = file.readlines() - -# Estrarre le informazioni dalle prime 7 righe -if len(lines) >= 7: - tipo_centralina = lines[1].split()[0] # Prima stringa nella seconda riga - nome_unit = lines[1].split()[1] # Seconda stringa nella seconda riga - ip_centralina = lines[2].split()[1] # IP della centralina dalla terza riga - ip_gateway = lines[4].split()[1] # IP del gateway dalla quinta riga - path_tool = lines[5].strip() # Path completo dalla sesta riga - nome_tool = path_tool.split('/')[-1].replace('.csv', '') # Ultima parte del percorso senza estensione - tipo_tool = path_tool.split('/')[-2] # Parte precedente al nome_tool - -else: - raise ValueError("Il file non contiene abbastanza righe per estrarre i dati richiesti.") - -records = [] -# Elabora le righe dei dati a partire dalla riga 8 in poi -for line in lines[7:]: - # Rimuovi spazi bianchi o caratteri di nuova riga - input_data = line.strip() - - # Suddividi la stringa in sezioni usando ";|;" come separatore - parts = input_data.split(';|;') - - # Verifica che ci siano almeno tre parti (timestamp, misure e nodi) - if len(parts) < 3: - print(f"Riga non valida: {input_data}") - continue - - # Estrai la data/ora e le prime misurazioni - timestamp = parts[0] - measurements = parts[1] - - # Estrai i valori di ciascun nodo e formatta i dati come JSON - nodes = parts[2:] - node_list = [] - for i, node_data in enumerate(nodes, start=1): - node_dict = {"num": i} - # Dividi ogni nodo in valori separati da ";" - node_values = node_data.split(';') - for j, value in enumerate(node_values, start=0): - # Imposta i valori a -9999 se trovi "Dis." - node_dict['val' + str(j)] = -9999 if value == "Dis." else float(value) - node_list.append(node_dict) - - # Prepara i dati per l'inserimento/aggiornamento - record = { - "nome_unit": nome_unit.upper(), - "tipo_centralina": tipo_centralina, - "nome_tool": nome_tool.upper(), - "tipo_tool": tipo_tool, - "ip_centralina": ip_centralina, - "ip_gateway": ip_gateway, - "event_timestamp": timestamp, - "battery_level": float(measurements.split(';')[0]), - "temperature": float(measurements.split(';')[1]), - "nodes_jsonb": json.dumps(node_list) # Converti la lista di dizionari in una stringa JSON - } - - records.append(record) - - # Se abbiamo raggiunto 1000 record, esegui l'inserimento in batch - if len(records) >= 500: - print("raggiunti 500 record scrivo sul db") - write_db(engine, records) - records = [] - -write_db(engine, records) - -print("Tutte le righe del file sono state caricate con successo nella tabella PostgreSQL!") \ No newline at end of file diff --git a/dbddl/received.sql b/dbddl/received.sql new file mode 100644 index 0000000..55b1700 --- /dev/null +++ b/dbddl/received.sql @@ -0,0 +1,9 @@ +CREATE TABLE public.received +( + id serial4 NOT NULL, + filename text NULL, + "content" text NULL, + created_at timestamptz DEFAULT CURRENT_TIMESTAMP NULL, + loaded_at timestamptz NULL, + CONSTRAINT received_pk PRIMARY KEY (id) +); \ No newline at end of file diff --git a/dbddl/virtusers.sql b/dbddl/virtusers.sql new file mode 100644 index 0000000..930da41 --- /dev/null +++ b/dbddl/virtusers.sql @@ -0,0 +1,12 @@ +CREATE TABLE public.virtusers +( + id serial4 NOT NULL, + ftpuser text NOT NULL, + hash text NOT NULL, + virtpath text NOT NULL, + perm text NOT NULL, + defined_at timestamptz DEFAULT CURRENT_TIMESTAMP NULL, + deleted_at timestamptz NULL, + CONSTRAINT virtusers_pk PRIMARY KEY (id), + CONSTRAINT virtusers_unique UNIQUE (ftpuser) +); \ No newline at end of file diff --git a/ftpReceiver/demonize_ftpd.py b/demonize_ftpd.py similarity index 100% rename from ftpReceiver/demonize_ftpd.py rename to demonize_ftpd.py diff --git a/ftpReceiver/ftpcsvreceiver.ini b/ftpcsvreceiver.ini similarity index 89% rename from ftpReceiver/ftpcsvreceiver.ini rename to ftpcsvreceiver.ini index 0b5901e..c6039b5 100644 --- a/ftpReceiver/ftpcsvreceiver.ini +++ b/ftpcsvreceiver.ini @@ -26,5 +26,8 @@ password = batt1l0 dbName = asedb dbSchema = public - tableName = virtusers - defaultPerm = elmw \ No newline at end of file + userTableName = virtusers + recTableName = received + +[unit] + Header = G801:7|G802:0 \ No newline at end of file diff --git a/ftppylog.log b/ftppylog.log new file mode 100644 index 0000000..1b6cd04 --- /dev/null +++ b/ftppylog.log @@ -0,0 +1,636 @@ +2024-11-16 16:11:17,867 concurrency model: async +2024-11-16 16:11:17,867 masquerade (NAT) address: 0.0.0.0 +2024-11-16 16:11:17,867 passive ports: 40000->40499 +2024-11-16 16:11:17,867 >>> starting FTP server on 0.0.0.0:2121, pid=43875 <<< +2024-11-16 16:27:10,428 127.0.0.1:39908-[] FTP session opened (connect) +2024-11-16 16:27:23,845 127.0.0.1:39908-[] USER 'alex' failed login. +2024-11-16 16:27:37,885 127.0.0.1:39908-[] FTP session closed (disconnect). +2024-11-16 16:27:40,594 127.0.0.1:54702-[] FTP session opened (connect) +2024-11-16 16:28:01,891 127.0.0.1:54702-[admin] USER 'admin' logged in. +2024-11-16 16:32:05,716 127.0.0.1:54702-[admin] FTP session closed (disconnect). +2024-11-16 16:32:06,836 127.0.0.1:45522-[] FTP session opened (connect) +2024-11-16 16:32:18,426 127.0.0.1:45522-[admin] USER 'admin' logged in. +2024-11-16 16:37:42,902 127.0.0.1:45522-[admin] Control connection timed out. +2024-11-16 16:37:42,903 127.0.0.1:45522-[admin] FTP session closed (disconnect). +2024-11-16 16:40:54,452 127.0.0.1:34776-[] FTP session opened (connect) +2024-11-16 16:41:03,491 127.0.0.1:34776-[admin] USER 'admin' logged in. +2024-11-16 16:42:13,781 User pippo created. +2024-11-16 16:46:49,602 User paperino created. +2024-11-16 16:51:51,502 127.0.0.1:34776-[admin] Control connection timed out. +2024-11-16 16:51:51,503 127.0.0.1:34776-[admin] FTP session closed (disconnect). +2024-11-16 17:00:02,414 127.0.0.1:47132-[] FTP session opened (connect) +2024-11-16 17:00:06,585 127.0.0.1:47132-[pippo] USER 'pippo' logged in. +2024-11-16 17:00:14,802 127.0.0.1:47132-[pippo] FTP session closed (disconnect). +2024-11-16 17:01:39,792 127.0.0.1:46978-[] FTP session opened (connect) +2024-11-16 17:01:39,808 127.0.0.1:46978-[pippo] USER 'pippo' logged in. +2024-11-16 17:01:42,279 127.0.0.1:46978-[pippo] FTP session closed (disconnect). +2024-11-16 17:54:58,728 concurrency model: async +2024-11-16 17:54:58,728 masquerade (NAT) address: 0.0.0.0 +2024-11-16 17:54:58,728 passive ports: 40000->40499 +2024-11-16 17:54:58,728 >>> starting FTP server on 0.0.0.0:2121, pid=14473 <<< +2024-11-16 17:55:10,031 127.0.0.1:42816-[] FTP session opened (connect) +2024-11-16 17:55:19,438 127.0.0.1:42816-[admin] USER 'admin' logged in. +2024-11-16 17:55:58,822 User pippo created. +2024-11-16 17:56:05,111 User minnie created. +2024-11-16 17:56:14,786 User paperino created. +2024-11-16 18:02:00,650 127.0.0.1:42816-[admin] Control connection timed out. +2024-11-16 18:02:00,650 127.0.0.1:42816-[admin] FTP session closed (disconnect). +2024-11-16 18:02:46,446 received interrupt signal +2024-11-16 18:02:46,446 >>> shutting down FTP server, 1 socket(s), pid=14473 <<< +2024-11-17 10:04:28,065 concurrency model: async +2024-11-17 10:04:28,066 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:04:28,066 passive ports: 40000->40499 +2024-11-17 10:04:28,066 >>> starting FTP server on 0.0.0.0:2121, pid=17006 <<< +2024-11-17 10:06:17,632 received interrupt signal +2024-11-17 10:06:17,633 >>> shutting down FTP server, 1 socket(s), pid=17006 <<< +2024-11-17 10:06:59,331 concurrency model: async +2024-11-17 10:06:59,331 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:06:59,332 passive ports: 40000->40499 +2024-11-17 10:06:59,332 >>> starting FTP server on 0.0.0.0:2121, pid=17255 <<< +2024-11-17 10:07:19,546 127.0.0.1:55312-[] FTP session opened (connect) +2024-11-17 10:07:19,584 127.0.0.1:55312-[pippo] USER 'pippo' logged in. +2024-11-17 10:07:52,070 127.0.0.1:55312-[pippo] FTP session closed (disconnect). +2024-11-17 10:13:52,720 received interrupt signal +2024-11-17 10:13:52,720 >>> shutting down FTP server, 1 socket(s), pid=17255 <<< +2024-11-17 10:15:04,736 concurrency model: async +2024-11-17 10:15:04,736 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:15:04,736 passive ports: 40000->40499 +2024-11-17 10:15:04,736 >>> starting FTP server on 0.0.0.0:2121, pid=17939 <<< +2024-11-17 10:15:24,440 127.0.0.1:52982-[] FTP session opened (connect) +2024-11-17 10:15:37,937 127.0.0.1:52982-[admin] USER 'admin' logged in. +2024-11-17 10:17:24,635 received interrupt signal +2024-11-17 10:17:24,636 >>> shutting down FTP server, 2 socket(s), pid=17939 <<< +2024-11-17 10:17:24,636 127.0.0.1:52982-[admin] FTP session closed (disconnect). +2024-11-17 10:17:26,268 concurrency model: async +2024-11-17 10:17:26,268 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:17:26,269 passive ports: 40000->40499 +2024-11-17 10:17:26,269 >>> starting FTP server on 0.0.0.0:2121, pid=18149 <<< +2024-11-17 10:17:31,056 127.0.0.1:45368-[] FTP session opened (connect) +2024-11-17 10:17:38,908 127.0.0.1:45368-[admin] USER 'admin' logged in. +2024-11-17 10:17:45,678 User manu created. +2024-11-17 10:17:50,636 received interrupt signal +2024-11-17 10:17:50,637 >>> shutting down FTP server, 2 socket(s), pid=18149 <<< +2024-11-17 10:17:50,637 127.0.0.1:45368-[admin] FTP session closed (disconnect). +2024-11-17 10:22:11,226 concurrency model: async +2024-11-17 10:22:11,227 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:22:11,227 passive ports: 40000->40499 +2024-11-17 10:22:11,227 >>> starting FTP server on 0.0.0.0:2121, pid=18695 <<< +2024-11-17 10:22:17,395 127.0.0.1:43890-[] FTP session opened (connect) +2024-11-17 10:22:24,487 127.0.0.1:43890-[admin] USER 'admin' logged in. +2024-11-17 10:23:30,831 received interrupt signal +2024-11-17 10:23:30,832 >>> shutting down FTP server, 2 socket(s), pid=18695 <<< +2024-11-17 10:23:30,832 127.0.0.1:43890-[admin] FTP session closed (disconnect). +2024-11-17 10:23:51,371 concurrency model: async +2024-11-17 10:23:51,371 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:23:51,372 passive ports: 40000->40499 +2024-11-17 10:23:51,372 >>> starting FTP server on 0.0.0.0:2121, pid=18872 <<< +2024-11-17 10:23:56,133 127.0.0.1:48262-[] FTP session opened (connect) +2024-11-17 10:24:04,039 127.0.0.1:48262-[admin] USER 'admin' logged in. +2024-11-17 10:24:14,799 unhandled exception in instance +Traceback (most recent call last): + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 83, in read + obj.handle_read_event() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 420, in handle_read_event + self.handle_read() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/ioloop.py", line 967, in handle_read + asynchat.async_chat.handle_read(self) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asynchat/__init__.py", line 171, in handle_read + self.found_terminator() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1574, in found_terminator + self.pre_process_command(line, cmd, arg) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1693, in pre_process_command + self.process_command(cmd, arg, **kwargs) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1704, in process_command + method(*args, **kwargs) + File "/home/alex/devel/ASE/ftpReceiver/./FtpCsvReceiver.py", line 212, in ftp_SITE_ADDU + password = parms[1] # Get the password + ~~~~~^^^ +IndexError: list index out of range +2024-11-17 10:24:14,814 127.0.0.1:48262-[admin] FTP session closed (disconnect). +2024-11-17 10:25:25,926 received interrupt signal +2024-11-17 10:25:25,926 >>> shutting down FTP server, 1 socket(s), pid=18872 <<< +2024-11-17 10:25:27,581 concurrency model: async +2024-11-17 10:25:27,581 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:25:27,581 passive ports: 40000->40499 +2024-11-17 10:25:27,581 >>> starting FTP server on 0.0.0.0:2121, pid=19042 <<< +2024-11-17 10:25:31,759 127.0.0.1:33094-[] FTP session opened (connect) +2024-11-17 10:25:40,460 127.0.0.1:33094-[admin] USER 'admin' logged in. +2024-11-17 10:29:23,587 received interrupt signal +2024-11-17 10:29:23,587 >>> shutting down FTP server, 2 socket(s), pid=19042 <<< +2024-11-17 10:29:23,587 127.0.0.1:33094-[admin] FTP session closed (disconnect). +2024-11-17 10:29:24,728 concurrency model: async +2024-11-17 10:29:24,728 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:29:24,728 passive ports: 40000->40499 +2024-11-17 10:29:24,728 >>> starting FTP server on 0.0.0.0:2121, pid=19376 <<< +2024-11-17 10:29:33,579 127.0.0.1:57836-[] FTP session opened (connect) +2024-11-17 10:29:42,553 127.0.0.1:57836-[admin] USER 'admin' logged in. +2024-11-17 10:29:51,214 User manu created. +2024-11-17 10:30:52,649 received interrupt signal +2024-11-17 10:30:52,649 >>> shutting down FTP server, 2 socket(s), pid=19376 <<< +2024-11-17 10:30:52,650 127.0.0.1:57836-[admin] FTP session closed (disconnect). +2024-11-17 10:30:54,369 concurrency model: async +2024-11-17 10:30:54,369 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:30:54,369 passive ports: 40000->40499 +2024-11-17 10:30:54,369 >>> starting FTP server on 0.0.0.0:2121, pid=19568 <<< +2024-11-17 10:30:59,944 127.0.0.1:40356-[] FTP session opened (connect) +2024-11-17 10:31:07,745 127.0.0.1:40356-[admin] USER 'admin' logged in. +2024-11-17 10:31:23,119 unhandled exception in instance +Traceback (most recent call last): + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 83, in read + obj.handle_read_event() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 420, in handle_read_event + self.handle_read() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/ioloop.py", line 967, in handle_read + asynchat.async_chat.handle_read(self) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asynchat/__init__.py", line 171, in handle_read + self.found_terminator() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1574, in found_terminator + self.pre_process_command(line, cmd, arg) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1693, in pre_process_command + self.process_command(cmd, arg, **kwargs) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1704, in process_command + method(*args, **kwargs) + File "/home/alex/devel/ASE/ftpReceiver/./FtpCsvReceiver.py", line 212, in ftp_SITE_ADDU + password = parms[1] # Get the password + ~~~~~^^^ +IndexError: list index out of range +2024-11-17 10:31:23,127 127.0.0.1:40356-[admin] FTP session closed (disconnect). +2024-11-17 10:31:32,521 received interrupt signal +2024-11-17 10:31:32,521 >>> shutting down FTP server, 1 socket(s), pid=19568 <<< +2024-11-17 10:37:54,245 concurrency model: async +2024-11-17 10:37:54,245 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:37:54,245 passive ports: 40000->40499 +2024-11-17 10:37:54,247 >>> starting FTP server on 0.0.0.0:2121, pid=20113 <<< +2024-11-17 10:37:59,530 127.0.0.1:53630-[] FTP session opened (connect) +2024-11-17 10:38:07,619 127.0.0.1:53630-[admin] USER 'admin' logged in. +2024-11-17 10:38:20,170 unhandled exception in instance +Traceback (most recent call last): + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 83, in read + obj.handle_read_event() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 420, in handle_read_event + self.handle_read() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/ioloop.py", line 967, in handle_read + asynchat.async_chat.handle_read(self) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asynchat/__init__.py", line 171, in handle_read + self.found_terminator() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1574, in found_terminator + self.pre_process_command(line, cmd, arg) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1693, in pre_process_command + self.process_command(cmd, arg, **kwargs) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1704, in process_command + method(*args, **kwargs) + File "/home/alex/devel/ASE/ftpReceiver/./FtpCsvReceiver.py", line 216, in ftp_SITE_ADDU + password = parms[1] # Get the password + ~~~~~^^^ +IndexError: list index out of range +2024-11-17 10:38:20,178 127.0.0.1:53630-[admin] FTP session closed (disconnect). +2024-11-17 10:39:14,707 received interrupt signal +2024-11-17 10:39:14,708 >>> shutting down FTP server, 1 socket(s), pid=20113 <<< +2024-11-17 10:39:17,371 concurrency model: async +2024-11-17 10:39:17,371 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:39:17,371 passive ports: 40000->40499 +2024-11-17 10:39:17,371 >>> starting FTP server on 0.0.0.0:2121, pid=20247 <<< +2024-11-17 10:39:22,049 127.0.0.1:56728-[] FTP session opened (connect) +2024-11-17 10:39:31,320 127.0.0.1:56728-[admin] USER 'admin' logged in. +2024-11-17 10:41:14,770 received interrupt signal +2024-11-17 10:41:14,770 >>> shutting down FTP server, 2 socket(s), pid=20247 <<< +2024-11-17 10:41:14,771 127.0.0.1:56728-[admin] FTP session closed (disconnect). +2024-11-17 10:42:39,883 concurrency model: async +2024-11-17 10:42:39,883 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:42:39,883 passive ports: 40000->40499 +2024-11-17 10:42:39,883 >>> starting FTP server on 0.0.0.0:2121, pid=20650 <<< +2024-11-17 10:42:45,881 127.0.0.1:40566-[] FTP session opened (connect) +2024-11-17 10:42:54,757 127.0.0.1:40566-[admin] USER 'admin' logged in. +2024-11-17 10:43:13,533 User manu created. +2024-11-17 10:43:26,148 127.0.0.1:40566-[admin] FTP session closed (disconnect). +2024-11-17 10:43:28,647 received interrupt signal +2024-11-17 10:43:28,647 >>> shutting down FTP server, 1 socket(s), pid=20650 <<< +2024-11-17 10:55:54,214 concurrency model: async +2024-11-17 10:55:54,214 masquerade (NAT) address: 0.0.0.0 +2024-11-17 10:55:54,214 passive ports: 40000->40499 +2024-11-17 10:55:54,214 >>> starting FTP server on 0.0.0.0:2121, pid=21382 <<< +2024-11-17 10:55:57,828 127.0.0.1:44966-[] FTP session opened (connect) +2024-11-17 10:56:07,172 127.0.0.1:44966-[admin] USER 'admin' logged in. +2024-11-17 10:56:36,699 127.0.0.1:44966-[admin] FTP session closed (disconnect). +2024-11-17 10:56:38,142 127.0.0.1:58452-[] FTP session opened (connect) +2024-11-17 10:56:45,770 127.0.0.1:58452-[] USER 'manu' failed login. +2024-11-17 10:56:48,023 127.0.0.1:58452-[] FTP session closed (disconnect). +2024-11-17 10:56:48,770 127.0.0.1:54228-[] FTP session opened (connect) +2024-11-17 10:56:52,416 127.0.0.1:54228-[manu] USER 'manu' logged in. +2024-11-17 10:57:15,198 127.0.0.1:54228-[manu] FTP session closed (disconnect). +2024-11-17 11:01:37,872 received interrupt signal +2024-11-17 11:01:37,872 >>> shutting down FTP server, 1 socket(s), pid=21382 <<< +2024-11-17 11:31:20,091 concurrency model: async +2024-11-17 11:31:20,093 masquerade (NAT) address: 0.0.0.0 +2024-11-17 11:31:20,093 passive ports: 40000->40499 +2024-11-17 11:31:20,093 >>> starting FTP server on 0.0.0.0:2121, pid=24597 <<< +2024-11-17 11:31:37,453 127.0.0.1:40144-[] FTP session opened (connect) +2024-11-17 11:31:37,465 127.0.0.1:40144-[pippo] USER 'pippo' logged in. +2024-11-17 11:33:07,546 127.0.0.1:54682-[] FTP session opened (connect) +2024-11-17 11:33:07,573 127.0.0.1:54682-[pippo] USER 'pippo' logged in. +2024-11-17 11:33:07,583 127.0.0.1:54682-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:33:07,586 127.0.0.1:54682-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.0 +2024-11-17 11:33:07,607 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0028_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:33:10,963 127.0.0.1:54682-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.004 +2024-11-17 11:33:10,977 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0029_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:33:12,457 127.0.0.1:54682-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.004 +2024-11-17 11:33:12,488 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0030_20241106104859.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:34:12,482 127.0.0.1:54682-[pippo] FTP session closed (disconnect). +2024-11-17 11:35:10,197 127.0.0.1:59894-[] FTP session opened (connect) +2024-11-17 11:35:10,213 127.0.0.1:59894-[pippo] USER 'pippo' logged in. +2024-11-17 11:35:10,230 127.0.0.1:59894-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:35:12,851 127.0.0.1:59894-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.001 +2024-11-17 11:35:12,865 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0028_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:35:16,132 127.0.0.1:59894-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.002 +2024-11-17 11:35:16,172 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0029_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:35:19,305 127.0.0.1:59894-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.001 +2024-11-17 11:35:19,352 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0030_20241106104859.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:35:56,111 received interrupt signal +2024-11-17 11:35:56,111 >>> shutting down FTP server, 3 socket(s), pid=24597 <<< +2024-11-17 11:35:56,112 127.0.0.1:40144-[pippo] FTP session closed (disconnect). +2024-11-17 11:35:56,112 127.0.0.1:59894-[pippo] FTP session closed (disconnect). +2024-11-17 11:35:57,603 concurrency model: async +2024-11-17 11:35:57,603 masquerade (NAT) address: 0.0.0.0 +2024-11-17 11:35:57,603 passive ports: 40000->40499 +2024-11-17 11:35:57,603 >>> starting FTP server on 0.0.0.0:2121, pid=25083 <<< +2024-11-17 11:36:10,963 127.0.0.1:38240-[] FTP session opened (connect) +2024-11-17 11:36:10,997 127.0.0.1:38240-[pippo] USER 'pippo' logged in. +2024-11-17 11:36:10,998 127.0.0.1:38240-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:36:13,846 127.0.0.1:40098-[] FTP session opened (connect) +2024-11-17 11:36:13,854 127.0.0.1:40098-[pippo] USER 'pippo' logged in. +2024-11-17 11:36:13,855 127.0.0.1:40098-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:36:15,578 127.0.0.1:40098-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.0 +2024-11-17 11:36:15,591 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0030_20241106104859.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:36:18,044 127.0.0.1:40098-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.002 +2024-11-17 11:36:18,089 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0029_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:36:20,047 127.0.0.1:40098-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.0 +2024-11-17 11:36:20,066 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0028_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:36:44,381 received interrupt signal +2024-11-17 11:36:44,381 >>> shutting down FTP server, 3 socket(s), pid=25083 <<< +2024-11-17 11:36:44,381 127.0.0.1:38240-[pippo] FTP session closed (disconnect). +2024-11-17 11:36:44,382 127.0.0.1:40098-[pippo] FTP session closed (disconnect). +2024-11-17 11:37:17,358 concurrency model: async +2024-11-17 11:37:17,359 masquerade (NAT) address: 0.0.0.0 +2024-11-17 11:37:17,359 passive ports: 40000->40499 +2024-11-17 11:37:17,359 >>> starting FTP server on 0.0.0.0:2121, pid=25277 <<< +2024-11-17 11:37:21,159 127.0.0.1:58104-[] FTP session opened (connect) +2024-11-17 11:37:21,182 127.0.0.1:58104-[pippo] USER 'pippo' logged in. +2024-11-17 11:37:21,194 127.0.0.1:58104-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:37:22,610 127.0.0.1:58104-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.001 +2024-11-17 11:37:22,655 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0028_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:37:25,175 127.0.0.1:58104-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.003 +2024-11-17 11:37:25,332 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0029_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:37:27,363 127.0.0.1:58104-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.002 +2024-11-17 11:37:27,409 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0030_20241106104859.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:38:08,944 127.0.0.1:58104-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.0 +2024-11-17 11:38:08,975 File <_io.TextIOWrapper name='/home/alex/aseftp/pippo/DT0028_20241106044856.csv' mode='r' encoding='UTF-8'> not loaded. Held in user path. +2024-11-17 11:39:09,030 127.0.0.1:58104-[pippo] FTP session closed (disconnect). +2024-11-17 11:40:20,851 received interrupt signal +2024-11-17 11:40:20,851 >>> shutting down FTP server, 1 socket(s), pid=25277 <<< +2024-11-17 11:40:22,232 concurrency model: async +2024-11-17 11:40:22,232 masquerade (NAT) address: 0.0.0.0 +2024-11-17 11:40:22,233 passive ports: 40000->40499 +2024-11-17 11:40:22,233 >>> starting FTP server on 0.0.0.0:2121, pid=25648 <<< +2024-11-17 11:40:26,195 127.0.0.1:53810-[] FTP session opened (connect) +2024-11-17 11:40:26,202 127.0.0.1:53810-[pippo] USER 'pippo' logged in. +2024-11-17 11:40:26,208 127.0.0.1:53810-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:40:27,646 127.0.0.1:53810-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.001 +2024-11-17 11:40:27,686 File /home/alex/aseftp/pippo/DT0028_20241106044856.csv loaded: removed. +2024-11-17 11:40:31,967 127.0.0.1:53810-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.0 +2024-11-17 11:40:31,999 File /home/alex/aseftp/pippo/DT0030_20241106104859.csv loaded: removed. +2024-11-17 11:40:34,741 127.0.0.1:53810-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.003 +2024-11-17 11:40:34,847 File /home/alex/aseftp/pippo/DT0029_20241106044856.csv loaded: removed. +2024-11-17 11:41:34,787 127.0.0.1:53810-[pippo] FTP session closed (disconnect). +2024-11-17 11:42:34,983 received interrupt signal +2024-11-17 11:42:34,984 >>> shutting down FTP server, 1 socket(s), pid=25648 <<< +2024-11-17 11:43:03,231 concurrency model: async +2024-11-17 11:43:03,231 masquerade (NAT) address: 0.0.0.0 +2024-11-17 11:43:03,231 passive ports: 40000->40499 +2024-11-17 11:43:03,231 >>> starting FTP server on 0.0.0.0:2121, pid=26036 <<< +2024-11-17 11:43:16,274 127.0.0.1:55572-[] FTP session opened (connect) +2024-11-17 11:43:16,285 127.0.0.1:55572-[pippo] USER 'pippo' logged in. +2024-11-17 11:43:23,683 127.0.0.1:33298-[] FTP session opened (connect) +2024-11-17 11:43:23,696 127.0.0.1:33298-[pippo] USER 'pippo' logged in. +2024-11-17 11:43:23,711 127.0.0.1:33298-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 11:43:23,713 127.0.0.1:33298-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.0 +2024-11-17 11:43:23,736 File /home/alex/aseftp/pippo/DT0028_20241106044856.csv loaded: removed. +2024-11-17 11:43:25,805 127.0.0.1:33298-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.002 +2024-11-17 11:43:25,904 File /home/alex/aseftp/pippo/DT0029_20241106044856.csv loaded: removed. +2024-11-17 11:43:28,197 127.0.0.1:33298-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.0 +2024-11-17 11:43:28,220 File /home/alex/aseftp/pippo/DT0030_20241106104859.csv loaded: removed. +2024-11-17 11:44:07,155 127.0.0.1:33298-[pippo] FTP session closed (disconnect). +2024-11-17 11:44:07,155 127.0.0.1:55572-[pippo] FTP session closed (disconnect). +2024-11-17 14:59:05,461 concurrency model: async +2024-11-17 14:59:05,461 masquerade (NAT) address: 0.0.0.0 +2024-11-17 14:59:05,461 passive ports: 40000->40499 +2024-11-17 14:59:05,461 >>> starting FTP server on 0.0.0.0:2121, pid=6675 <<< +2024-11-17 14:59:18,071 127.0.0.1:36752-[] FTP session opened (connect) +2024-11-17 14:59:28,077 127.0.0.1:36752-[admin] USER 'admin' logged in. +2024-11-17 14:59:58,032 User manu deleted. +2024-11-17 15:02:07,073 User manu deleted. +2024-11-17 15:02:30,264 received interrupt signal +2024-11-17 15:02:30,264 >>> shutting down FTP server, 2 socket(s), pid=6675 <<< +2024-11-17 15:02:30,265 127.0.0.1:36752-[admin] FTP session closed (disconnect). +2024-11-17 15:02:31,387 concurrency model: async +2024-11-17 15:02:31,387 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:02:31,387 passive ports: 40000->40499 +2024-11-17 15:02:31,387 >>> starting FTP server on 0.0.0.0:2121, pid=7643 <<< +2024-11-17 15:02:36,000 127.0.0.1:33844-[] FTP session opened (connect) +2024-11-17 15:02:43,345 127.0.0.1:33844-[admin] USER 'admin' logged in. +2024-11-17 15:02:56,563 User manu deleted. +2024-11-17 15:03:43,366 received interrupt signal +2024-11-17 15:03:43,367 >>> shutting down FTP server, 2 socket(s), pid=7643 <<< +2024-11-17 15:03:43,367 127.0.0.1:33844-[admin] FTP session closed (disconnect). +2024-11-17 15:03:45,031 concurrency model: async +2024-11-17 15:03:45,031 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:03:45,031 passive ports: 40000->40499 +2024-11-17 15:03:45,031 >>> starting FTP server on 0.0.0.0:2121, pid=7794 <<< +2024-11-17 15:04:00,031 127.0.0.1:50034-[] FTP session opened (connect) +2024-11-17 15:04:09,519 127.0.0.1:50034-[admin] USER 'admin' logged in. +2024-11-17 15:07:50,335 received interrupt signal +2024-11-17 15:07:50,335 >>> shutting down FTP server, 2 socket(s), pid=7794 <<< +2024-11-17 15:07:50,336 127.0.0.1:50034-[admin] FTP session closed (disconnect). +2024-11-17 15:07:51,676 concurrency model: async +2024-11-17 15:07:51,676 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:07:51,676 passive ports: 40000->40499 +2024-11-17 15:07:51,676 >>> starting FTP server on 0.0.0.0:2121, pid=8075 <<< +2024-11-17 15:08:03,457 127.0.0.1:40972-[] FTP session opened (connect) +2024-11-17 15:08:11,999 127.0.0.1:40972-[admin] USER 'admin' logged in. +2024-11-17 15:08:20,851 User manu deleted. +2024-11-17 15:08:36,519 User manu created. +2024-11-17 15:09:59,725 received interrupt signal +2024-11-17 15:09:59,725 >>> shutting down FTP server, 2 socket(s), pid=8075 <<< +2024-11-17 15:09:59,726 127.0.0.1:40972-[admin] FTP session closed (disconnect). +2024-11-17 15:35:49,835 concurrency model: async +2024-11-17 15:35:49,835 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:35:49,835 passive ports: 40000->40499 +2024-11-17 15:35:49,835 >>> starting FTP server on 0.0.0.0:2121, pid=10690 <<< +2024-11-17 15:36:00,189 127.0.0.1:53868-[] FTP session opened (connect) +2024-11-17 15:36:12,027 127.0.0.1:53868-[] USER 'admin' failed login. +2024-11-17 15:36:14,787 127.0.0.1:53868-[] FTP session closed (disconnect). +2024-11-17 15:36:18,450 received interrupt signal +2024-11-17 15:36:18,450 >>> shutting down FTP server, 1 socket(s), pid=10690 <<< +2024-11-17 15:37:24,318 concurrency model: async +2024-11-17 15:37:24,319 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:37:24,319 passive ports: 40000->40499 +2024-11-17 15:37:24,319 >>> starting FTP server on 0.0.0.0:2121, pid=10909 <<< +2024-11-17 15:37:27,677 127.0.0.1:46094-[] FTP session opened (connect) +2024-11-17 15:37:37,187 127.0.0.1:46094-[admin] USER 'admin' logged in. +2024-11-17 15:38:11,262 User manu deleted. +2024-11-17 15:38:15,758 User pippo deleted. +2024-11-17 15:38:20,085 User pluto deleted. +2024-11-17 15:38:24,120 User paperino deleted. +2024-11-17 15:38:31,644 User minnie deleted. +2024-11-17 15:38:41,004 127.0.0.1:46094-[admin] FTP session closed (disconnect). +2024-11-17 15:38:44,575 received interrupt signal +2024-11-17 15:38:44,575 >>> shutting down FTP server, 1 socket(s), pid=10909 <<< +2024-11-17 15:38:45,703 concurrency model: async +2024-11-17 15:38:45,703 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:38:45,703 passive ports: 40000->40499 +2024-11-17 15:38:45,703 >>> starting FTP server on 0.0.0.0:2121, pid=11004 <<< +2024-11-17 15:38:49,997 127.0.0.1:37248-[] FTP session opened (connect) +2024-11-17 15:38:58,140 127.0.0.1:37248-[admin] USER 'admin' logged in. +2024-11-17 15:39:07,272 User manu created. +2024-11-17 15:39:13,411 User pippo created. +2024-11-17 15:39:18,283 User pluto created. +2024-11-17 15:43:56,919 127.0.0.1:37248-[admin] FTP session closed (disconnect). +2024-11-17 15:43:59,267 received interrupt signal +2024-11-17 15:43:59,267 >>> shutting down FTP server, 1 socket(s), pid=11004 <<< +2024-11-17 15:47:36,542 concurrency model: async +2024-11-17 15:47:36,542 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:47:36,542 passive ports: 40000->40499 +2024-11-17 15:47:36,542 >>> starting FTP server on 0.0.0.0:2121, pid=11565 <<< +2024-11-17 15:48:00,312 127.0.0.1:59378-[] FTP session opened (connect) +2024-11-17 15:48:08,488 127.0.0.1:59378-[admin] USER 'admin' logged in. +2024-11-17 15:48:45,267 received interrupt signal +2024-11-17 15:48:45,268 >>> shutting down FTP server, 2 socket(s), pid=11565 <<< +2024-11-17 15:48:45,268 127.0.0.1:59378-[admin] FTP session closed (disconnect). +2024-11-17 15:57:19,893 concurrency model: async +2024-11-17 15:57:19,893 masquerade (NAT) address: 0.0.0.0 +2024-11-17 15:57:19,893 passive ports: 40000->40499 +2024-11-17 15:57:19,893 >>> starting FTP server on 0.0.0.0:2121, pid=12188 <<< +2024-11-17 15:57:24,990 127.0.0.1:55434-[] FTP session opened (connect) +2024-11-17 15:57:35,187 127.0.0.1:55434-[admin] USER 'admin' logged in. +2024-11-17 15:59:50,118 received interrupt signal +2024-11-17 15:59:50,119 >>> shutting down FTP server, 2 socket(s), pid=12188 <<< +2024-11-17 15:59:50,119 127.0.0.1:55434-[admin] FTP session closed (disconnect). +2024-11-17 16:00:08,367 concurrency model: async +2024-11-17 16:00:08,367 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:00:08,367 passive ports: 40000->40499 +2024-11-17 16:00:08,367 >>> starting FTP server on 0.0.0.0:2121, pid=12471 <<< +2024-11-17 16:00:12,812 127.0.0.1:57856-[] FTP session opened (connect) +2024-11-17 16:00:20,412 127.0.0.1:57856-[admin] USER 'admin' logged in. +2024-11-17 16:02:37,802 received interrupt signal +2024-11-17 16:02:37,802 >>> shutting down FTP server, 2 socket(s), pid=12471 <<< +2024-11-17 16:02:37,802 127.0.0.1:57856-[admin] FTP session closed (disconnect). +2024-11-17 16:02:38,812 concurrency model: async +2024-11-17 16:02:38,812 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:02:38,812 passive ports: 40000->40499 +2024-11-17 16:02:38,812 >>> starting FTP server on 0.0.0.0:2121, pid=12768 <<< +2024-11-17 16:02:44,183 127.0.0.1:60768-[] FTP session opened (connect) +2024-11-17 16:02:51,754 127.0.0.1:60768-[admin] USER 'admin' logged in. +2024-11-17 16:04:22,062 received interrupt signal +2024-11-17 16:04:22,062 >>> shutting down FTP server, 2 socket(s), pid=12768 <<< +2024-11-17 16:04:22,063 127.0.0.1:60768-[admin] FTP session closed (disconnect). +2024-11-17 16:04:23,113 concurrency model: async +2024-11-17 16:04:23,113 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:04:23,113 passive ports: 40000->40499 +2024-11-17 16:04:23,113 >>> starting FTP server on 0.0.0.0:2121, pid=12899 <<< +2024-11-17 16:04:29,098 127.0.0.1:36128-[] FTP session opened (connect) +2024-11-17 16:04:37,672 127.0.0.1:36128-[admin] USER 'admin' logged in. +2024-11-17 16:06:42,754 received interrupt signal +2024-11-17 16:06:42,754 >>> shutting down FTP server, 2 socket(s), pid=12899 <<< +2024-11-17 16:06:42,754 127.0.0.1:36128-[admin] FTP session closed (disconnect). +2024-11-17 16:06:44,484 concurrency model: async +2024-11-17 16:06:44,484 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:06:44,484 passive ports: 40000->40499 +2024-11-17 16:06:44,484 >>> starting FTP server on 0.0.0.0:2121, pid=13116 <<< +2024-11-17 16:06:49,883 127.0.0.1:35480-[] FTP session opened (connect) +2024-11-17 16:06:59,525 127.0.0.1:35480-[admin] USER 'admin' logged in. +2024-11-17 16:07:36,980 received interrupt signal +2024-11-17 16:07:36,980 >>> shutting down FTP server, 2 socket(s), pid=13116 <<< +2024-11-17 16:07:36,981 127.0.0.1:35480-[admin] FTP session closed (disconnect). +2024-11-17 16:08:10,476 concurrency model: async +2024-11-17 16:08:10,476 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:08:10,477 passive ports: 40000->40499 +2024-11-17 16:08:10,477 >>> starting FTP server on 0.0.0.0:2121, pid=13272 <<< +2024-11-17 16:08:15,257 127.0.0.1:54896-[] FTP session opened (connect) +2024-11-17 16:08:22,020 127.0.0.1:54896-[admin] USER 'admin' logged in. +2024-11-17 16:08:31,126 User manu deleted. +2024-11-17 16:10:13,934 received interrupt signal +2024-11-17 16:10:13,934 >>> shutting down FTP server, 2 socket(s), pid=13272 <<< +2024-11-17 16:10:13,935 127.0.0.1:54896-[admin] FTP session closed (disconnect). +2024-11-17 16:10:15,282 concurrency model: async +2024-11-17 16:10:15,282 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:10:15,282 passive ports: 40000->40499 +2024-11-17 16:10:15,282 >>> starting FTP server on 0.0.0.0:2121, pid=13463 <<< +2024-11-17 16:10:19,570 127.0.0.1:43226-[] FTP session opened (connect) +2024-11-17 16:10:29,067 127.0.0.1:43226-[admin] USER 'admin' logged in. +2024-11-17 16:10:39,372 User manu created. +2024-11-17 16:10:42,548 User manu1 created. +2024-11-17 16:10:45,550 User manu2 created. +2024-11-17 16:11:06,295 User manu2 deleted. +2024-11-17 16:11:13,269 User manu1 deleted. +2024-11-17 16:11:21,341 127.0.0.1:43226-[admin] FTP session closed (disconnect). +2024-11-17 16:12:01,236 127.0.0.1:41182-[] FTP session opened (connect) +2024-11-17 16:12:04,252 127.0.0.1:41182-[] USER 'pippo' failed login. +2024-11-17 16:12:04,285 127.0.0.1:41182-[] FTP session closed (disconnect). +2024-11-17 16:12:36,983 127.0.0.1:40066-[] FTP session opened (connect) +2024-11-17 16:12:39,989 127.0.0.1:40066-[] USER 'pippo' failed login. +2024-11-17 16:12:39,991 127.0.0.1:40066-[] FTP session closed (disconnect). +2024-11-17 16:12:58,124 127.0.0.1:51388-[] FTP session opened (connect) +2024-11-17 16:13:08,168 127.0.0.1:51388-[] USER 'pippo' failed login. +2024-11-17 16:15:26,046 received interrupt signal +2024-11-17 16:15:26,046 >>> shutting down FTP server, 2 socket(s), pid=13463 <<< +2024-11-17 16:15:26,046 127.0.0.1:51388-[] FTP session closed (disconnect). +2024-11-17 16:15:27,602 concurrency model: async +2024-11-17 16:15:27,602 masquerade (NAT) address: 0.0.0.0 +2024-11-17 16:15:27,602 passive ports: 40000->40499 +2024-11-17 16:15:27,602 >>> starting FTP server on 0.0.0.0:2121, pid=13831 <<< +2024-11-17 16:15:33,707 127.0.0.1:38210-[] FTP session opened (connect) +2024-11-17 16:15:43,131 127.0.0.1:38210-[] USER 'pippo' failed login. +2024-11-17 16:15:56,572 127.0.0.1:38210-[] FTP session closed (disconnect). +2024-11-17 16:16:02,656 127.0.0.1:54374-[] FTP session opened (connect) +2024-11-17 16:16:06,769 127.0.0.1:54374-[pippo] USER 'pippo' logged in. +2024-11-17 16:16:25,281 127.0.0.1:43068-[] FTP session opened (connect) +2024-11-17 16:16:25,282 127.0.0.1:43068-[pippo] USER 'pippo' logged in. +2024-11-17 16:16:31,330 127.0.0.1:43068-[pippo] DELE /home/alex/aseftp/pippo/aaa 550 'Not enough privileges.' +2024-11-17 16:16:38,759 127.0.0.1:39462-[] FTP session opened (connect) +2024-11-17 16:16:38,771 127.0.0.1:39462-[pippo] USER 'pippo' logged in. +2024-11-17 16:16:38,790 127.0.0.1:39462-[pippo] CWD /home/alex/aseftp/pippo 250 +2024-11-17 16:16:38,796 127.0.0.1:39462-[pippo] STOR /home/alex/aseftp/pippo/DT0028_20241106044856.csv completed=1 bytes=732 seconds=0.004 +2024-11-17 16:16:38,822 File /home/alex/aseftp/pippo/DT0028_20241106044856.csv loaded: removed. +2024-11-17 16:16:41,634 127.0.0.1:39462-[pippo] STOR /home/alex/aseftp/pippo/DT0029_20241106044856.csv completed=1 bytes=319344 seconds=0.005 +2024-11-17 16:16:41,811 File /home/alex/aseftp/pippo/DT0029_20241106044856.csv loaded: removed. +2024-11-17 16:16:44,426 127.0.0.1:39462-[pippo] STOR /home/alex/aseftp/pippo/DT0030_20241106104859.csv completed=1 bytes=558 seconds=0.004 +2024-11-17 16:16:44,452 File /home/alex/aseftp/pippo/DT0030_20241106104859.csv loaded: removed. +2024-11-17 16:17:15,495 127.0.0.1:39462-[pippo] FTP session closed (disconnect). +2024-11-17 16:17:15,495 127.0.0.1:43068-[pippo] FTP session closed (disconnect). +2024-11-17 16:18:03,811 received interrupt signal +2024-11-17 16:18:03,811 >>> shutting down FTP server, 2 socket(s), pid=13831 <<< +2024-11-17 16:18:03,812 127.0.0.1:54374-[pippo] FTP session closed (disconnect). +2024-11-22 18:30:27,518 concurrency model: async +2024-11-22 18:30:27,519 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:30:27,519 passive ports: 40000->40499 +2024-11-22 18:30:27,519 >>> starting FTP server on 0.0.0.0:2121, pid=8022 <<< +2024-11-22 18:30:47,568 127.0.0.1:43280-[] FTP session opened (connect) +2024-11-22 18:31:01,659 127.0.0.1:43280-[admin] USER 'admin' logged in. +2024-11-22 18:36:01,722 127.0.0.1:43280-[admin] Control connection timed out. +2024-11-22 18:36:01,723 127.0.0.1:43280-[admin] FTP session closed (disconnect). +2024-11-22 18:37:14,605 127.0.0.1:34284-[] FTP session opened (connect) +2024-11-22 18:37:24,293 127.0.0.1:34284-[admin] USER 'admin' logged in. +2024-11-22 18:37:48,152 127.0.0.1:34284-[admin] FTP session closed (disconnect). +2024-11-22 18:39:34,075 received interrupt signal +2024-11-22 18:39:34,075 >>> shutting down FTP server, 1 socket(s), pid=8022 <<< +2024-11-22 18:39:36,502 concurrency model: async +2024-11-22 18:39:36,502 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:39:36,502 passive ports: 40000->40499 +2024-11-22 18:39:36,503 >>> starting FTP server on 0.0.0.0:2121, pid=8412 <<< +2024-11-22 18:39:39,746 127.0.0.1:42256-[] FTP session opened (connect) +2024-11-22 18:39:47,806 127.0.0.1:42256-[admin] USER 'admin' logged in. +2024-11-22 18:44:58,973 received interrupt signal +2024-11-22 18:44:58,974 >>> shutting down FTP server, 2 socket(s), pid=8412 <<< +2024-11-22 18:44:58,974 127.0.0.1:42256-[admin] FTP session closed (disconnect). +2024-11-22 18:45:00,402 concurrency model: async +2024-11-22 18:45:00,402 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:45:00,402 passive ports: 40000->40499 +2024-11-22 18:45:00,402 >>> starting FTP server on 0.0.0.0:2121, pid=8737 <<< +2024-11-22 18:45:05,019 127.0.0.1:47502-[] FTP session opened (connect) +2024-11-22 18:45:12,713 127.0.0.1:47502-[admin] USER 'admin' logged in. +2024-11-22 18:45:33,133 User pluto deleted. +2024-11-22 18:46:09,856 received interrupt signal +2024-11-22 18:46:09,857 >>> shutting down FTP server, 2 socket(s), pid=8737 <<< +2024-11-22 18:46:09,857 127.0.0.1:47502-[admin] FTP session closed (disconnect). +2024-11-22 18:46:10,985 concurrency model: async +2024-11-22 18:46:10,985 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:46:10,985 passive ports: 40000->40499 +2024-11-22 18:46:10,985 >>> starting FTP server on 0.0.0.0:2121, pid=8865 <<< +2024-11-22 18:46:43,455 127.0.0.1:33630-[] FTP session opened (connect) +2024-11-22 18:46:54,881 127.0.0.1:33630-[admin] USER 'admin' logged in. +2024-11-22 18:49:36,259 received interrupt signal +2024-11-22 18:49:36,259 >>> shutting down FTP server, 2 socket(s), pid=8865 <<< +2024-11-22 18:49:36,260 127.0.0.1:33630-[admin] FTP session closed (disconnect). +2024-11-22 18:49:37,612 concurrency model: async +2024-11-22 18:49:37,612 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:49:37,612 passive ports: 40000->40499 +2024-11-22 18:49:37,612 >>> starting FTP server on 0.0.0.0:2121, pid=9150 <<< +2024-11-22 18:49:44,462 127.0.0.1:40772-[] FTP session opened (connect) +2024-11-22 18:50:01,599 127.0.0.1:40772-[admin] USER 'admin' logged in. +2024-11-22 18:53:09,872 received interrupt signal +2024-11-22 18:53:09,873 >>> shutting down FTP server, 2 socket(s), pid=9150 <<< +2024-11-22 18:53:09,873 127.0.0.1:40772-[admin] FTP session closed (disconnect). +2024-11-22 18:53:11,525 concurrency model: async +2024-11-22 18:53:11,525 masquerade (NAT) address: 0.0.0.0 +2024-11-22 18:53:11,525 passive ports: 40000->40499 +2024-11-22 18:53:11,525 >>> starting FTP server on 0.0.0.0:2121, pid=9359 <<< +2024-11-22 18:53:17,754 127.0.0.1:46428-[] FTP session opened (connect) +2024-11-22 18:53:25,777 127.0.0.1:46428-[admin] USER 'admin' logged in. +2024-11-22 18:53:54,739 received interrupt signal +2024-11-22 18:53:54,739 >>> shutting down FTP server, 2 socket(s), pid=9359 <<< +2024-11-22 18:53:54,740 127.0.0.1:46428-[admin] FTP session closed (disconnect). +2024-11-22 19:24:09,627 concurrency model: async +2024-11-22 19:24:09,627 masquerade (NAT) address: 0.0.0.0 +2024-11-22 19:24:09,628 passive ports: 40000->40499 +2024-11-22 19:24:09,628 >>> starting FTP server on 0.0.0.0:2121, pid=11233 <<< +2024-11-22 19:24:16,186 127.0.0.1:49948-[] FTP session opened (connect) +2024-11-22 19:24:24,997 127.0.0.1:49948-[admin] USER 'admin' logged in. +2024-11-22 19:24:30,383 unhandled exception in instance +Traceback (most recent call last): + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 83, in read + obj.handle_read_event() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asyncore/__init__.py", line 420, in handle_read_event + self.handle_read() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/ioloop.py", line 967, in handle_read + asynchat.async_chat.handle_read(self) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/asynchat/__init__.py", line 171, in handle_read + self.found_terminator() + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1574, in found_terminator + self.pre_process_command(line, cmd, arg) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1693, in pre_process_command + self.process_command(cmd, arg, **kwargs) + File "/home/alex/devel/ASE/.venv/lib/python3.12/site-packages/pyftpdlib/handlers.py", line 1704, in process_command + method(*args, **kwargs) +TypeError: ASEHandler.ftp_SITE_LSTU() takes 1 positional argument but 2 were given +2024-11-22 19:24:30,389 127.0.0.1:49948-[admin] FTP session closed (disconnect). +2024-11-22 19:24:58,787 received interrupt signal +2024-11-22 19:24:58,787 >>> shutting down FTP server, 1 socket(s), pid=11233 <<< +2024-11-22 19:25:18,308 concurrency model: async +2024-11-22 19:25:18,308 masquerade (NAT) address: 0.0.0.0 +2024-11-22 19:25:18,308 passive ports: 40000->40499 +2024-11-22 19:25:18,308 >>> starting FTP server on 0.0.0.0:2121, pid=11451 <<< +2024-11-22 19:25:22,119 127.0.0.1:34480-[] FTP session opened (connect) +2024-11-22 19:25:29,692 127.0.0.1:34480-[admin] USER 'admin' logged in. +2024-11-22 19:25:39,787 User pippo restored. +2024-11-22 19:25:47,538 User pluto restored. +2024-11-22 19:25:55,113 User pluto deleted. +2024-11-22 19:26:10,426 127.0.0.1:34480-[admin] FTP session closed (disconnect). +2024-11-23 21:46:17,010 127.0.0.1:38162-[] FTP session opened (connect) +2024-11-23 21:46:25,394 127.0.0.1:38162-[admin] USER 'admin' logged in. +2024-11-23 21:46:47,555 User pluto restored. +2024-11-23 21:47:08,483 127.0.0.1:38162-[admin] FTP session closed (disconnect). +2024-11-23 21:49:32,894 received interrupt signal +2024-11-23 21:49:32,895 >>> shutting down FTP server, 1 socket(s), pid=11451 <<< +2024-11-23 21:59:00,767 concurrency model: async +2024-11-23 21:59:00,767 masquerade (NAT) address: 0.0.0.0 +2024-11-23 21:59:00,767 passive ports: 40000->40499 +2024-11-23 21:59:00,767 >>> starting FTP server on 0.0.0.0:2121, pid=55913 <<< +2024-11-23 21:59:05,027 127.0.0.1:57894-[] FTP session opened (connect) +2024-11-23 21:59:12,976 127.0.0.1:57894-[admin] USER 'admin' logged in. +2024-11-23 21:59:45,717 127.0.0.1:57894-[admin] FTP session closed (disconnect). +2024-11-23 21:59:49,861 127.0.0.1:59362-[] FTP session opened (connect) +2024-11-23 21:59:58,109 127.0.0.1:59362-[admin] USER 'admin' logged in. +2024-11-23 22:00:22,292 127.0.0.1:59362-[admin] FTP session closed (disconnect). +2024-11-23 22:04:12,171 received interrupt signal +2024-11-23 22:04:12,171 >>> shutting down FTP server, 1 socket(s), pid=55913 <<< +2024-11-23 22:04:13,913 concurrency model: async +2024-11-23 22:04:13,913 masquerade (NAT) address: 0.0.0.0 +2024-11-23 22:04:13,913 passive ports: 40000->40499 +2024-11-23 22:04:13,913 >>> starting FTP server on 0.0.0.0:2121, pid=57624 <<< +2024-11-23 22:04:21,175 127.0.0.1:45764-[] FTP session opened (connect) +2024-11-23 22:04:34,054 127.0.0.1:45764-[admin] USER 'admin' logged in. +2024-11-23 22:04:57,850 User simo created. +2024-11-23 22:07:58,794 User simo deleted. +2024-11-23 22:08:11,548 User simo restored. +2024-11-23 22:08:58,923 127.0.0.1:45764-[admin] FTP session closed (disconnect). +2024-11-23 22:12:57,013 received interrupt signal +2024-11-23 22:12:57,014 >>> shutting down FTP server, 1 socket(s), pid=57624 <<< diff --git a/prova.py b/prova.py new file mode 100755 index 0000000..602a0ca --- /dev/null +++ b/prova.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +from utils.config import set_config as setting + +cfg = setting.config() + +print(cfg.header["G801"], cfg.header["G802"]) \ No newline at end of file diff --git a/transform_file.py b/transform_file.py new file mode 100644 index 0000000..0cb4b01 --- /dev/null +++ b/transform_file.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python3 + +import sys +import os + +import json +import psycopg2 + +import logging + +from sqlalchemy import create_engine, text +from utils.time import timestamp_fmt as ts +from utils.config import set_config as setting + +def write_db(engine, records): + with engine.connect() as conn: + conn.execute(text(""" + INSERT INTO dataraw (nome_unit, tipo_centralina, nome_tool, tipo_tool, ip_centralina, ip_gateway, event_timestamp, battery_level, temperature, nodes_jsonb) + VALUES + """ + ",".join([ + f"(:{i}_nome_unit, :{i}_tipo_centralina, :{i}_nome_tool, :{i}_tipo_tool, :{i}_ip_centralina, :{i}_ip_gateway, :{i}_event_timestamp, :{i}_battery_level, :{i}_temperature, :{i}_nodes_jsonb)" + for i in range(len(records)) + ]) + """ + ON CONFLICT ON CONSTRAINT dataraw_unique + DO UPDATE SET + tipo_centralina = EXCLUDED.tipo_centralina, + tipo_tool = EXCLUDED.tipo_tool, + ip_centralina = EXCLUDED.ip_centralina, + ip_gateway = EXCLUDED.ip_gateway, + battery_level = EXCLUDED.battery_level, + temperature = EXCLUDED.temperature, + nodes_jsonb = EXCLUDED.nodes_jsonb; + """), {f"{i}_{key}": value for i, record in enumerate(records) for key, value in record.items()}) + + conn.commit() + +def elab_csv(engine, cfg): + # Leggi il file intero e separa l'intestazione dal resto dei dati + with open('DT0029_20241106044856.csv', 'r') as file: + lines = file.readlines() + + # Estrarre le informazioni dalle prime 7 righe + if len(lines) >= cfg.header(G801): + tipo_centralina = lines[1].split()[0] # Prima stringa nella seconda riga + nome_unit = lines[1].split()[1] # Seconda stringa nella seconda riga + ip_centralina = lines[2].split()[1] # IP della centralina dalla terza riga + ip_gateway = lines[4].split()[1] # IP del gateway dalla quinta riga + path_tool = lines[5].strip() # Path completo dalla sesta riga + nome_tool = path_tool.split('/')[-1].replace('.csv', '') # Ultima parte del percorso senza estensione + tipo_tool = path_tool.split('/')[-2] # Parte precedente al nome_tool + + else: + + logging.info(f'Il file non contiene abbastanza righe per estrarre i dati richiesti.') + raise ValueError("Il file non contiene abbastanza righe per estrarre i dati richiesti.") + + records = [] + # Elabora le righe dei dati a partire dalla riga 8 in poi + for line in lines[7:]: + # Rimuovi spazi bianchi o caratteri di nuova riga + input_data = line.strip() + + # Suddividi la stringa in sezioni usando ";|;" come separatore + parts = input_data.split(';|;') + + # Verifica che ci siano almeno tre parti (timestamp, misure e nodi) + if len(parts) < 3: + print(f"Riga non valida: {input_data}") + continue + + # Estrai la data/ora e le prime misurazioni + timestamp = parts[0] + measurements = parts[1] + + # Estrai i valori di ciascun nodo e formatta i dati come JSON + nodes = parts[2:] + node_list = [] + for i, node_data in enumerate(nodes, start=1): + node_dict = {"num": i} + # Dividi ogni nodo in valori separati da ";" + node_values = node_data.split(';') + for j, value in enumerate(node_values, start=0): + # Imposta i valori a -9999 se trovi "Dis." + node_dict['val' + str(j)] = -9999 if value == "Dis." else float(value) + node_list.append(node_dict) + + # Prepara i dati per l'inserimento/aggiornamento + record = { + "nome_unit": nome_unit.upper(), + "tipo_centralina": tipo_centralina, + "nome_tool": nome_tool.upper(), + "tipo_tool": tipo_tool, + "ip_centralina": ip_centralina, + "ip_gateway": ip_gateway, + "event_timestamp": timestamp, + "battery_level": float(measurements.split(';')[0]), + "temperature": float(measurements.split(';')[1]), + "nodes_jsonb": json.dumps(node_list) # Converti la lista di dizionari in una stringa JSON + } + + records.append(record) + + # Se abbiamo raggiunto 500 record, esegui l'inserimento in batch + if len(records) >= 500: + print("raggiunti 500 record scrivo sul db") + write_db(engine, records) + records = [] + + write_db(engine, records) + + +def main(): + # Load the configuration settings + cfg = setting.config() + + try: + # Configura la connessione al database PostgreSQL + engine = create_engine(f'postgresql://{cfg.dbuser}:{cfg.dbpass}@{cfg.dbhost}:{cfg.dbport}/{cfg.dbschema}') + # Configure logging + logging.basicConfig( + format="%(asctime)s %(message)s", + filename=cfg.logfilename, + level=logging.INFO, + ) + elab_csv(engine, cfg) + + except KeyboardInterrupt: + logging.info( + "Info: {}.".format("Shutdown requested...exiting") + ) + + except Exception: + print( + "{} - PID {:>5} >> Error: {}.".format( + ts.timestamp("log"), os.getpid(), sys.exc_info()[1] + ) + ) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ftpReceiver/utils/__init__.py b/utils/__init__.py similarity index 100% rename from ftpReceiver/utils/__init__.py rename to utils/__init__.py diff --git a/ftpReceiver/utils/config/__init__.py b/utils/config/__init__.py similarity index 100% rename from ftpReceiver/utils/config/__init__.py rename to utils/config/__init__.py diff --git a/ftpReceiver/utils/config/set_config.py b/utils/config/set_config.py similarity index 79% rename from ftpReceiver/utils/config/set_config.py rename to utils/config/set_config.py index 50fe9c3..4f22af2 100644 --- a/ftpReceiver/utils/config/set_config.py +++ b/utils/config/set_config.py @@ -2,13 +2,13 @@ """ from configparser import ConfigParser - +import json class config: def __init__(self): c = ConfigParser() c.read(["/etc/aseftp/ftpcsvreceiver.ini", "./ftpcsvreceiver.ini", - "./ase-receiver/ase-receiver/ftpcsvreceiver.ini"]) + "./ftpReceiver/ftpcsvreceiver.ini"]) # FTP setting self.firstport = c.getint("ftpserver", "firstPort") self.logfilename = c.get("ftpserver", "logFilename") @@ -34,4 +34,8 @@ class config: self.dbpass = c.get("db", "password") self.dbname = c.get("db", "dbName") self.dbschema = c.get("db", "dbSchema") - self.dbtable = c.get("db", "tableName") + self.dbusertable = c.get("db", "userTableName") + self.dbrectable = c.get("db", "recTableName") + + # csv unit setting + self.header = {key: int(value) for pair in c.get("unit", "Header").split('|') for key, value in [pair.split(':')]} diff --git a/ftpReceiver/utils/parsers/G801_parser.py b/utils/parsers/G801_parser.py similarity index 100% rename from ftpReceiver/utils/parsers/G801_parser.py rename to utils/parsers/G801_parser.py diff --git a/ftpReceiver/utils/parsers/__init__.py b/utils/parsers/__init__.py similarity index 100% rename from ftpReceiver/utils/parsers/__init__.py rename to utils/parsers/__init__.py diff --git a/ftpReceiver/utils/time/__init__.py b/utils/time/__init__.py similarity index 100% rename from ftpReceiver/utils/time/__init__.py rename to utils/time/__init__.py diff --git a/ftpReceiver/utils/time/date_refmt.py b/utils/time/date_refmt.py similarity index 100% rename from ftpReceiver/utils/time/date_refmt.py rename to utils/time/date_refmt.py diff --git a/ftpReceiver/utils/time/dt_convert.py b/utils/time/dt_convert.py similarity index 100% rename from ftpReceiver/utils/time/dt_convert.py rename to utils/time/dt_convert.py diff --git a/ftpReceiver/utils/time/timestamp_fmt.py b/utils/time/timestamp_fmt.py similarity index 100% rename from ftpReceiver/utils/time/timestamp_fmt.py rename to utils/time/timestamp_fmt.py