The code below 1. Identifies files that are created in a directory and 2. Uploads them to my webserver.
My problem is that the program is only successful when I copy and paste a file into the directory "path_to_watch". The program fails when I use a third-party program (NBA Live 06) that creates files in the "path_to_watch" directory.
The error I receive is: "PermissionError: [Errno 13] Permission denied: 'filename.txt'"
import os, time
from ftplib import FTP
def idFiles():
path_to_watch = r"c:\Users\User\gamestats"
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while True:
time.sleep (1)
after = dict ([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after if not f in before]
if added:
## edit filename to prepare for upload
upload = str(", ".join (added))
ftp = FTP('www.website.com')
ftp.login(user='username', passwd='password')
ftp.cwd('archives')
## error is called on this following line
ftp.storbinary('STOR ' + upload, open(upload, 'rb'))
#resets timer
before = after
idFiles()
Many thanks in advance for any help.