Expand|Select|Wrap|Line Numbers
- 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)
- #self.ftp.sendcmd('LIST')
- for line in data:
- try:
- self.date_str = ' '.join(line.split()[5:8])
- #newDate = datetime.datetime.strptime(self.date_str,'%b %d %H:%M')
- 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 value is Aug 20 11:12, but year is missing,
so Bydefault year value it is taking 1900, which is not correct.
To debug it, i logged in ftp server and did dir / ls in both the cases it is showing timestamp like 'Aug 20 11:12'. But if i do ls -lTr, in that case it is showing year,
what i want is some how i can pass above command to ftp and get the result.
Is there any python ftplib module's function that can do this.