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

50 lines
1.4 KiB
Python
Raw Normal View History

2018-10-28 01:03:38 +00:00
from ftplib import FTP
2018-10-30 23:21:49 +00:00
from ftplib import all_errors
2018-10-28 01:03:38 +00:00
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")
2018-10-31 01:29:17 +00:00
ftp = FTP(host, timeout=300)
2018-10-28 01:03:38 +00:00
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")
2018-10-30 23:21:49 +00:00
except all_errors:
2018-10-28 01:03:38 +00:00
file.close()
os.remove(qwkfile)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage python qwknetftpc.py config.ini")
exit(1)
2018-10-31 01:29:17 +00:00
server = dostuff(sys.argv[1])