My main goal is to check an FTP server at anytime for a new file hits and then generate a .txt file with only the new files copied there. If there are no new files then it returns nothing. Here is what I have so far. I have started by copying the files from the server into oldlist.txt, then connecting to the FTP site and comparing data from newlist.txt and oldlist.txt and the differences I want in Temporary FTP file changes.txt. Each time I connect I will change newlist.txt and make it the oldlist.txt so that I can compare the next time I connect. Is there a better way to do this? My lists seem to never change data each time. Sorry if this is confusing thanks.
import os
filename = "oldlist.txt"
testing = "newlist.txt"
tempfilename = "Temporary FTP file Changes.txt"
old = open(filename, "r")
oldlist = old.readlines()
oldlist.sort()
from ftplib import FTP
ftp = FTP("ftpsite", "username", "password")
ftp.set_pasv(False)
newlist = []
ftp.dir(newlist.append)
newlist.sort()
ftp.close()
bob = open(testing, "w")
for nl in newlist:
bob.write(nl + "\n")
hello = open(tempfilename, "w")
for c in newlist:
if c not in oldlist:
hello.write(c + "\n")
bob.close()
old.close()
hello.close()
os.remove("oldlist.txt")
os.rename("newlist.txt", "oldlist.txt")