def startConnection(self):
from ftplib import FTP
self.ftp = FTP(self.loginServer)
print 'Loging In'
print self.ftp.login(self.username, self.password)
data = []
self.ftp.dir(data.append)
for line in data:
try:
self.date_str = ' '.join(line.split()[5:8])
newDate = time.strptime(self.date_str,'%b %d %H:%M')
print newDate
col_list = line.split()
name = col_list[0]
tempDir = {}
if name.startswith('d'):
tempDir['directory'] = newDate
else:
tempDir['file']=newDate
self.dirInfo[col_list[8]] = tempDir
except:
print "**********Exception for line **********\n" + line + "\n**********Exception End**********"
此函数运行良好,newDate 值为 Aug 20 11:12,但缺少年份,因此默认年份值为 1900,这是不正确的。为了调试它,我登录了 ftp 服务器并在两种情况下都执行了 dir / ls,它显示了像“Aug 20 11:12”这样的时间戳。但如果我执行 ls -lTr,在这种情况下,它会显示年份,
我想要的是如何将上述命令传递给 ftp 并获得结果。是否有任何 python ftplib 模块的功能可以做到这一点。