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