Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import gzip
- from glob import glob
- from ftplib import FTP_TLS
- from zipfile import ZipFile
- import xml.etree.ElementTree as ElementTree
- import html
- import pandas as pd
- import numpy as np
- from slugify import slugify
- # Konfiguration
- ftp_host = "ip"
- ftp_user = "user"
- ftp_password = "pass"
- filepath_root_remote = "/public_html/export"
- filepath_root_local = "P:/Pfad/Onlineshop/Sitemap"
- file_list_name = "P:/Pfad/Onlineshop/Sitemap/Python-Dateiimport.csv"
- # Verbindung mit FTP-Server aufbauen
- ftp = FTP_TLS(ftp_host)
- ftp.auth()
- ftp.login(user=ftp_user, passwd=ftp_password)
- ftp.prot_p()
- # Verbindung mit FTP-Server aufbauen
- ftp = FTP_TLS(ftp_host)
- ftp.auth()
- ftp.login(user=ftp_user, passwd=ftp_password)
- ftp.prot_p()
- # Liste der herunterzuladenen Dateien durchlaufen
- file_list = pd.read_csv(file_list_name, sep=";")
- for i, row in file_list.iterrows():
- filename_zip = ".xml.gz"
- filename_xml_src = "%s.xml" % row["Dateiname"]
- filename_xml_dest = "%s.xml" % (row["Dateiname"])
- filepath_remote = filepath_root_remote + "/%s%s" % (row["Dateiname"], filename_zip)
- filepath_local = "%s/%s" % (filepath_root_local, row["Dateiname"]) + filename_zip
- # Zip Datei herunterladen
- with open(filepath_local, "wb") as file_local:
- ftp.retrbinary("RETR %s" % filepath_remote, file_local.write)
- # XML Datei entpacken
- zip_ref = ZipFile(filepath_local, "r")
- zip_ref.extract(filename_xml_src, path=filepath_root_local)
- zip_ref.close()
- # FTP Verbindung schliessen
- ftp.quit()
Add Comment
Please, Sign In to add comment