You can set a directory on uploads, there is a 'mailbox' but the CWD/PWD doesn't work, not sure about downloads, there aren't any directories there!
I'm afraid I don't know python, so might be totally wrong but something basically along these lines:
import os
import sys
import posixpath
import time
import datetime
#Bots modules
import botslib
import botsglobal
from botsconfig import *
class UserCommunicationClass(communication.ftp):
@botslib.log_session
def connect(self):
botslib.settimeout(botsglobal.ini.getint('settings','ftptimeout',10))
self.session = ftplib.FTP()
self.session.set_debuglevel(botsglobal.ini.getint('settings','ftpdebug',0)) #set debug level (0=no, 1=medium, 2=full debug)
self.session.set_pasv(not self.channeldict['ftpactive']) #active or passive ftp
self.session.connect(host=self.channeldict['host'],port=int(self.channeldict['port']))
self.session.login(user=self.channeldict['username'],passwd=self.channeldict['secret'],acct=self.channeldict['ftpaccount'])
def outcommunicate(self):
#get right filename_mask
filename_mask = self.channeldict['filename'] if self.channeldict['filename'] else '*'
mode = 'STOR ' # APPEnd fails
for row in botslib.query('''SELECT idta,filename,numberofresends
FROM ta
WHERE idta>%(rootidta)s
AND status=%(status)s
AND statust=%(statust)s
AND tochannel=%(tochannel)s
''',
{'tochannel':self.channeldict['idchannel'],'rootidta':botslib.get_minta4query(),
'status':FILEOUT,'statust':OK}):
try:
ta_from = botslib.OldTransaction(row['idta'])
ta_to = ta_from.copyta(status=EXTERNOUT)
tofilename = self.filename_formatter(filename_mask,ta_from)
fromfile = botslib.opendata(row['filename'], 'rb')
self.session.storbinary(mode + tofilename, fromfile)
fromfile.close()
except:
txt = botslib.txtexc()
# It immediately drops connection on success, need to pick up the output and find out if it is actually a success.
# For now leave in existing error handling.
ta_to.update(statust=ERROR,errortext=txt,filename='ftp:/'+posixpath.join(self.dirpath,tofilename),numberofresends=row['numberofresends']+1)
else:
ta_to.update(statust=DONE,filename='ftp:/'+posixpath.join(self.dirpath,tofilename),numberofresends=row['numberofresends']+1)
finally:
ta_from.update(statust=DONE)
def disconnect(self):
try:
self.session.quit()
except:
self.session.close()
botslib.settimeout(botsglobal.ini.getint('settings','globaltimeout',10))
Thanks
David