This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
magicka/utils/qwknet/qwknetftpc.py
2018-10-28 11:07:08 +10:00

51 lines
1.4 KiB
Python

from ftplib import FTP
from ftplib import error_perm
import configparser
import os
import sys
def dostuff(config_file):
config = configparser.ConfigParser()
config.read(config_file)
host = config.get("Main", "Ftp Server")
username = config.get("Main", "Ftp User")
password = config.get("Main", "Ftp Password")
ftp = FTP(host)
ftp.login(username, password)
repfile = config.get("Main", "Outbound") + "/" + config.get("Main", "Host") + ".REP"
exists = os.path.isfile(repfile)
if exists:
file = open(repfile, "rb")
ftp.storbinary("STOR " + config.get("Main", "Host") + ".REP", file)
file.close()
os.remove(repfile)
print("SENT: " + config.get("Main", "Host") + ".REP")
qwkfile = config.get("Main", "Inbound") + "/" + config.get("Main", "Host") + ".QWK"
with open(qwkfile, 'wb') as file:
def callback(data):
file.write(data)
try:
ftp.retrbinary("RETR " + config.get("Main", "Host") + ".QWK", callback)
file.close()
print("RETREIVED: " + config.get("Main", "Host") + ".QWK")
except error_perm:
file.close()
os.remove(qwkfile)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage python qwknetftpc.py config.ini")
exit(1)
server = dostuff(sys.argv[1])