add doc in load ftp user

This commit is contained in:
2025-08-20 21:55:59 +02:00
parent 55383e51b8
commit 05816ee95d

View File

@@ -27,7 +27,11 @@ FTP_CONFIG = {
}
def connect_ftp() -> FTP:
"""Connessione al server FTP"""
"""
Establishes a connection to the FTP server using the predefined configuration.
Returns:
FTP: An active FTP connection object.
"""
try:
ftp = FTP()
ftp.connect(FTP_CONFIG['host'], FTP_CONFIG['port'])
@@ -39,7 +43,14 @@ def connect_ftp() -> FTP:
sys.exit(1)
def fetch_data_from_db(connection: mysql.connector.MySQLConnection) -> List[Tuple]:
"""Preleva i dati dal database"""
"""
Fetches username and password data from the 'ftp_accounts' table in the database.
Args:
connection (mysql.connector.MySQLConnection): The database connection object.
Returns:
List[Tuple]: A list of tuples, where each tuple contains (username, password).
"""
try:
cursor = connection.cursor()
@@ -62,6 +73,15 @@ def fetch_data_from_db(connection: mysql.connector.MySQLConnection) -> List[Tupl
cursor.close()
def send_site_command(ftp: FTP, command: str) -> bool:
"""
Sends a SITE command to the FTP server.
Args:
ftp (FTP): The FTP connection object.
command (str): The SITE command string to send (e.g., "ADDU username password").
Returns:
bool: True if the command was sent successfully, False otherwise.
"""
"""Invia un comando SITE al server FTP"""
try:
# Il comando SITE viene inviato usando sendcmd
@@ -73,7 +93,9 @@ def send_site_command(ftp: FTP, command: str) -> bool:
return False
def main():
"""Funzione principale"""
"""
Main function to connect to the database, fetch FTP user data, and send SITE ADDU commands to the FTP server.
"""
logger.info("Avvio script caricamento utenti FTP")
cfg = setting.Config()