0
下载不能在python中工作?使用python脚本从FTP位置下载目录/文件
我写了一个简单的python程序,为了从FTP位置获取文件,但是当我执行它时,它给出了错误[Errno 13] Permission denied message。
我的代码如下。任何想法为什么它不工作?
import ftplib
from ftplib import FTP, error_perm
def getFTPDir(dirpath):
f = ftplib.FTP(ip, username, password)
try:
f.cwd(dirpath)
nameList = f.nlst()
oldest = nameList[0]
newest = nameList[-1]
newest = oldest
newDirPath = dirpath +'/'+ newest
print f.cwd(newDirPath)
subNameList = f.nlst()
for i in range (len(subNameList)):
f.cwd(newDirPath + '/' + str(subNameList[i]))
nameList1 = f.nlst()
filename = nameList1[i]
print "downloading..............", filename
f.retrbinary('RETR '+ filename, open(os.path.join(destination,localPath),"wb").write)
print filename + " downloaded"
try:
fhandle = open(filename, 'wb')
f.retrbinary('RETR ' + filename, fhandle.write)
except Exception, e:
print str(e)
finally:
fhandle.close()
except error_perm:
return
except Exception, e:
print str(e)
finally:
f.close()
请在哪一行出现错误说...' –
f.retrbinary('RETR'+ filename,open – Dush