Ich muss mich jetzt nach längerer Zeit wieder mit meinem Tool rumschlagen. Leider hab ich mit Py2Exe eine Exe draus gemacht und den Quellcode verschlampt.
Ich hab folgendes als "ftpfilesorter.py" in den Lib Ordner kopiert:
Code: Alles auswählen
import ftplib
from operator import itemgetter
class Sorter(ftplib.FTP):
def __init__(self, host='', user='', passwd='', acct=''):
"""
Behaves like ftplib.FTP()
"""
ftplib.FTP.__init__(self, host, user, passwd, acct)
def datesort_files(self):
"""
Return a date-sorted file list from the current
ftp directory with the latest file on top
"""
files = []
for filename in self.nlst():
try:
mdtm = self.sendcmd('MDTM %s' % filename)
date = mdtm.split()[1]
files.append((filename, date))
except ftplib.error_perm:
pass
return sorted(files, key=itemgetter(1), reverse=True)
und das ist das auszuführende File:
Code: Alles auswählen
import os
from string import join as join
from shutil import rmtree as rmtree
from ftpsorter import *
from easygui import integerbox as integerbox
#Read data from config File
configfile = "config.csv"
exportpath = []
fpath = []
pdevice = []
plogin = []
ppassw = []
for line in open(configfile ,'rU'):
line = line.rstrip()
if line:
data = line.split(";")
exportpath.append(data)
fspath.append(data)
pdevice.append(data)
plogin.append(data)
ppassw.append(data)
exportpath = exportpath[0][0]
fpath = fpath[1][0]
pdevice = pdevice[2][0]
plogin = plogin[2][1]
ppassw = ppassw[2][2]
x=integerbox(msg=boxtext, title='fFTP Imp V0.1', default=1, argLowerBound=0, argUpperBound=99, image=None, root=None)
sorter = Sorter(pdevice ,plogin , ppassw)
sorter.cwd('/dat3')
#Delete path
rmtree(exportpath,1)
# das listet dir die dat-files geordnet nach datum auf:
sorter.datesort_files(pattern='*.dat', prettylines=True)
for x in range (0,x):
# wenn du mit dem dateinamen weiterarbeiten willst:
latest_dat, date = sorter.datesort_files(pattern='*.dat')[x]
latest_bin, date = sorter.datesort_files(pattern='*.bin')[x]
# If directory doesn't exist make it
if not os.path.isdir(exportpath):
os.mkdir(exportpath)
# Change the local directory to where you want to put the data
os.chdir(exportpath)
#write file to selected directory
sorter.retrbinary("RETR %s" % latest_dat, open(latest_dat,"wb").write)
sorter.retrbinary("RETR %s" % latest_bin, open(latest_bin,"wb").write)
file = open("datei" + str(x)+".txt",( "w") )
file.write(latest_dat)
x=x+1
file.close()
#cv.wait(10)
os.startfile(fpath)
Die Fehlermeldung lautet nun: got an unexpected keyword argument 'pattern'
Kann mir da jemand helfen?
Danke im Voraus.