我正在寻找FTP上文件夹中的特定文件。有几个文件夹,我的代码循环遍历每个文件夹以查找文件。有一次,我找到了我要下载的文件。
import ftplib
import os, sys, os.path
ftp = ftplib.FTP("xxxxxxxx")
ftp.login("dbaxyz", "password123")
files = []
try:
files = ftp.nlst()
except ftplib.error_perm, resp:
if str(resp) == "550 No files found":
print "No files in this directory"
else:
raise
for f in files:
filess = [],
filess=ftp.nlst(f)
for i in filess:
if len(i)==34 and i[8:11]=="ACO" and i[12:17]=="CCLF9" and i[3:7]=="1263" :
print i
local_filename = os.path.join('C:\\Users\\zubair.zahiruddin\\Desktop\\test', i)
file = open(local_filename, 'wb')
ftp.retrbinary('RETR '+ i, file.write)
file.close()
ftp.close()
#ftp.quit()
但是,我收到错误:找不到perm文件。
Traceback (most recent call last):
File "ftp.py", line 28, in <module>
ftp.retrbinary('RETR '+ i, file.write)
File "C:\Python27\lib\ftplib.py", line 414, in retrbinary
conn = self.transfercmd(cmd, rest)
File "C:\Python27\lib\ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Python27\lib\ftplib.py", line 339, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Python27\lib\ftplib.py", line 249, in sendcmd
return self.getresp()
File "C:\Python27\lib\ftplib.py", line 224, in getresp
raise error_perm, resp
ftplib.error_perm: 550 The system cannot find the file specified.
PS C:\ Users \ zubair.zahiruddin \ Desktop \ test&gt;