Files
DemonEditor/main/ftp.py

47 lines
1.4 KiB
Python
Raw Normal View History

2017-10-14 12:24:59 +03:00
from ftplib import FTP
import os
__DATA_FILES_LIST = ("tv", "radio", "lamedb")
def download_data(*, properties):
with FTP(properties["host"]) as ftp:
ftp.login(user=properties["user"], passwd=properties["password"])
save_path = properties["data_dir_path"]
# bouquets section
ftp.cwd(properties["services_path"])
files = []
ftp.dir(files.append)
2017-10-26 01:23:05 +03:00
2017-10-14 12:24:59 +03:00
for file in files:
name = str(file).strip()
if name.endswith(__DATA_FILES_LIST):
name = name.split()[-1]
with open(save_path + name, 'wb') as f:
ftp.retrbinary('RETR ' + name, f.write)
# satellites.xml section
ftp.cwd(properties["satellites_xml_path"])
files.clear()
ftp.dir(files.append)
2017-10-26 01:23:05 +03:00
2017-10-14 12:24:59 +03:00
for file in files:
name = str(file).strip()
xml_file = "satellites.xml"
if name.endswith(xml_file):
with open(save_path + xml_file, 'wb') as f:
ftp.retrbinary('RETR ' + xml_file, f.write)
2017-10-26 01:23:05 +03:00
2017-10-14 12:24:59 +03:00
return ftp.voidcmd("NOOP")
def upload_data(*, properties):
load_path = properties["data_dir_path"]
2017-10-26 01:23:05 +03:00
2017-10-14 12:24:59 +03:00
for file_name in os.listdir(load_path):
print(file_name)
# Open the file for transfer in binary mode
# f = open(file_name, "rb")
# transfer the file into receiver
# send = ftp.storbinary("STOR " + file_name, f)