【发布时间】:2015-09-23 20:35:26
【问题描述】:
下面的代码 1. 识别在目录中创建的文件 2. 将它们上传到我的网络服务器。
我的问题是程序只有在我将文件复制并粘贴到目录“path_to_watch”中时才会成功。当我使用在“path_to_watch”目录中创建文件的第三方程序(NBA Live 06)时,程序失败。
我收到的错误是:“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()
非常感谢您的帮助。
【问题讨论】:
标签: python upload python-3.4 ftplib