【发布时间】:2009-10-09 10:23:52
【问题描述】:
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 模块的函数可以做到这一点。
【问题讨论】: