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 の値は 8 月 20 日 11:12 ですが、年が欠落しているため、デフォルトの年の値は 1900 であり、これは正しくありません。それをデバッグするために、私は ftp サーバーにログインし、「8 月 20 日 11:12」のようなタイムスタンプを表示している両方のケースで dir / ls を実行しました。しかし、ls -lTr を実行すると、その場合は年が表示されます。
私が欲しいのは、上記のコマンドを ftp に渡して結果を得る方法です。これを実行できるpython ftplibモジュールの機能はありますか。