On 02/07/2012 11:34 PM, Rohan wrote:
> Hello,
>
> I have been using the BOTS program for a while but I am not going to
> pretend I have full knowledge so please bear with me.
>
> When I first looked at BOTS, some of the requirements for extra
> functionality that I had were coded as enhancments to the core
> software. However, recently I have been able to rework almost
> everything into external scripts and leave the core product untouched.
>
> The one thing I have been wrestling with that BOTS appears to be
> missing is the ability to FTP an output file with a temporary name,
> and then have it renamed at the end of the successful file transfer.
>
> This could be a file that is sent as "ORDERS000123.xml.tmp" and then
> renamed to "ORDERS000123.xml" at the completion of transfer as
> discussed in previous posts.
yes, I have seen this sort of ftp communication.
> As I understand it, I could take control of the FTP communication
> channel (by overriding the main and connect functions) and take full
> control - but it appears that this channel is executed one file at a
> time. I don't want to be connecting and disconnecting for every file
> sent.
I not sure what you have in mind here.
bots will transfers all edi file in one session.
> So my goals here are:
>
> a) I don't want to modify the core product if at all possible.
> b) Want FTP out channel to support a rename function.
>
> My questions are:
>
> a) Can I achieve this functionality right now? Is there something I
> am missing?
> b) Have you already put this in a future version? Perhaps it could be
> backported into my local scripts.
>
> I had previously programmed this as a user exit function in
> communication.py but I really want to avoid custom modifications.
send me the user user function, if it fits I will use it in bots.
henk-jan
your enhancement is nice!
but I will not use this in the main ftp flow (but will add it as user scripting), as it might break other server implementations.
hope you understand that I try to be very cautious here.
thank you!
henk-jan
On 02/08/2012 01:47 AM, Rohan wrote:
> You could always add a switch - "Add temp extension during transfer?"
> in the FTP options ;-)
the server apparently has implemented the file naming convention that *.tmp'-files are treated differently.
this seems to be very specific to this ftp-server.
if most or many ftp-servers would have such a file name convention, that would be great (convince me of that ;-)).
(I guess reason for all this is to have avoid reading of a file that is not completely written. There seems to be many conventions & solutions for this, all implementation dependent. Some ftp-servers
do not need such a mechanism at all, they know when a file is completly written)
> Anyway, to be totally clear, can I just confirm that you are adding:
>
> if self.userscript and hasattr(self.userscript,'rename'):
> tofilename =
> botslib.runscript(self.userscript,self.scriptname,'rename',
> channeldict=self.channeldict,filename=tofilename,ta=ta_from,session=self.session)
I will check this out and let you know.
henk-jan
yes I agree.
thanks for reminding me, I had not added this to my list.
henk-jan
Firstly I have a set of routescript functions (routescript.py) which
includes open_ftp() and close_ftp(). These are based on code in
communications.py and allow you to open an ftp session by just
specifying the channel. Then you can code other ftp commands to do
whatever you need. I also use this method to send remote commands to our
AS/400 system, delete files from servers, and monitor the number of
files queued on various servers, etc.
I create a routescript (Imports_Schenker.py) for the route, and in
postoutcommunication exit point, I establish a new ftp session and do
the renaming. You could just change the extension, or move them to
another folder, whatever is required.
An exit point built into bots might still be better, as you could use
the existing ftp session.
Kind Regards,
Mike
I think its good practice to use either a tmp directory or a temp filename or extension to overcome the issue of the system picking up files that are in the process of being transfered. I've come across several operational issues where this turned out to be the root cause.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+unsubscribe@googlegroups.com.
import bots.communication as communication
import bots.botslib as botslib
import bots.botsglobal as botsglobal
class ftp(communication.ftp):
def disconnect(self):
# files are in a temporary directory. Move them to final destination (rename)
for f in self.session.nlst():
self.session.rename(f,'../TEST2/%s' %f)
try:
self.session.quit()
except:
self.session.close()
botslib.settimeout(botsglobal.ini.getint('settings','globaltimeout',10))
Wouldn't it be great if this can be driven by parameters from the bots.ini to make it flexible for all bots userswithout the use of communicationscripts.
import bots.communication as communication
import bots.botslib as botslib
import bots.botsglobal as botsglobal
def filename(channeldict,ta,filename):
return 'tempupload/' + filename
class ftp(communication.ftp):
def disconnect(self):
# move files from tempupload subdirectory to parent directory (rename)
self.session.cwd('tempupload')
for f in self.session.nlst():
self.session.rename(f,'../%s' %f)
try:
self.session.quit()
except:
self.session.close()
botslib.settimeout(botsglobal.ini.getint('settings','globaltimeout',10))
Yes it should work in the same way for sftp. Just copy the sftp disconnect code from communication.py and modify it.
Yes it should work in the same way for sftp. Just copy the sftp disconnect code from communication.py and modify it.
--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
henk-jankind regards,think that also works for your use case.first use the tmp name, that a rename (this is users responsibility).what if there is field 'filename' (like now) and a field 'tmp filename'.hi Mike,thinking about this.
Yes, that is a better way. I also noticed this would get more complicated than I tought, eg with the '*' being replaced by counter.
Kind regards,
Henk-Jan
self.dirpath = self.session.pwd()
self.dirpath2 = self.session.pwd()
# lockname can set a temporary directory for uploads
if self.channeldict['lockname'] and not self.channeldict['lockname'].startswith('.') and self.channeldict['inorout'] == 'out':
self.dirpath = posixpath.normpath(posixpath.join(self.dirpath,self.channeldict['lockname']))
if self.channeldict['path']:
self.dirpath2 = posixpath.normpath(posixpath.join(self.dirpath2,self.channeldict['path']))
elif self.channeldict['path']:
self.dirpath = posixpath.normpath(posixpath.join(self.dirpath,self.channeldict['path']))
# append temporary file extension
if self.channeldict['lockname'] and self.channeldict['lockname'].startswith('.'):
tofilename += self.channeldict['lockname'] # rename files if lockname was used
if self.channeldict['lockname'] and self.channeldict['inorout'] == 'out':
if self.channeldict['lockname'].startswith('.'):
# remove temporary extension
l = 0-len(self.channeldict['lockname'])
for f in self.session.nlst():
if f.endswith(self.channeldict['lockname']):
self.session.rename(f,f[:l])
botsglobal.logger.debug('rename %s to %s',f,f[:l])
else:
# move files from temporary directory to path directory
for f in self.session.nlst():
self.session.rename(f,posixpath.join(self.dirpath2,f))
botsglobal.logger.debug('rename %s to %s',f,posixpath.join(self.dirpath2,f))