Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: timonkGood Day PG.
While the Lavastorm softare does not come with a node that functions as you describe out of the box, it does however include in the CORE library a "Python" node. This node allows for users to create their own nodes to fit specific project or graph needs.
For your convenience, I have pasted an example written by another user of how someone might use the Python node to implement an FTP node, with basic GET, PUT and LIST functions. Please feel free to use this as a guide, or as a solution if you feel it will help. Simply copy the text and paste it directly into the BRE editing pallette.
Please understand however, that only the nodes and libraries we release with our product are supported. We will support the basic function of the Python node, such that it operates as intended (interfaces correctly with and runs against a server), but we cannot support any custom work that users may do
with it.
Please let us know if you have further questions.
Regards
Timon Koufopoulos,
MDA Support.
node follows below ###
####
node:FTP
bretype:core::Python
editor:Label=FTP
editor:sortkey=46cc36f059c86d97_2
editor:icon=export.ico
inclock:/=Generate_reports
prop:Action=Get
prop:Binary=true
prop:LocalPath=C:\Documents and Settings\user\Desktop\brain data\worldseries.csv
prop:Password=guest
prop:Python2Implementation=<<EOX
import braininfo
import ftplib
import sys
import os.path
def ftpgrablines(line='', lines=[]):
if line:
lines.append(line)
else:
result = lines[:]
del lines[:]
return result
def setup(brainNodeControlObj, BrainNodeClass):
class BrainNode(BrainNodeClass):
def initialize(self):
super(BrainNode, self).initialize()
self.ftp = ftplib.FTP('{{^RemoteServer^}}', '{{^UserName^}}', '{{^Password^}}')
self.logInfo("initialized ftplib")
self.remote_path = '{{^RemotePath^}}'
self.local_path = os.path.normpath(r'{{^LocalPath=.^}}')
self.BinaryMode = '{{^Binary^}}'
self.PutOrGet = '{{^Action^}}'
if self.BinaryMode == "true":
self.opMode = 'wb'
else:
self.opMode = 'w'
def finalize(self, val):
super(BrainNode, self).finalize(val)
self.ftp.close()
# This will handle the data being downloaded
# It will be explained shortly
def handleDownload(self, block):
if self.BinaryMode == "true":
self.f.write(block)
else:
self.f.write(block + "\n")
def pump(self, quant):
if self.PutOrGet == "Get":
self.f = open(self.local_path, self.opMode)
self.ftp.retrlines('LIST')
if self.BinaryMode == "true":
self.ftp.retrbinary('RETR ' + self.remote_path, self.handleDownload)
else:
self.ftp.retrlines('RETR ' + self.remote_path, self.handleDownload)
self.f.close()
if self.PutOrGet == "Put":
self.f = open(self.local_path, 'r')
if self.BinaryMode == "true":
self.ftp.storbinary('STOR ' + self.remote_path, self.f)
else:
self.ftp.storlines('STOR ' + self.remote_path, self.f)
self.f.close()
if self.PutOrGet == "List":
om = self.newMetadata()
om.append("FileName","string")
#om.append("Size","string")
self.outputs[0].metadata = om
self.ftp.retrlines("NLST "+self.remote_path, ftpgrablines)
s = ftpgrablines()
for line in s:
rec = self.outputs[0].newRecord()
#rec["Size"] = self.ftp.size(line)
rec["FileName"] = line
self.outputs[0].write(rec)
return False
return BrainNode
EOX
prop:RemotePath=/worldseries.csv
prop:RemoteServer=ftp.lavastorm.com
prop:UserName=guest
editor:XY=750,60
editor:propdef=RemoteServer|string|1||None
editor:propdef=UserName|string|1||None
editor:propdef=Password|password|1||None
editor:propdef=Binary|boolean|1||None
editor:propdef=Action|choice|1||Put|Get|List
editor:propdef=RemotePath|string|1||None
editor:propdef=LocalPath|filename|1||None
editor:propoverride=Python2Implementation|2
editor:propdoc=RemotePath=Remote path+filename.
editor:propdoc=RemotePath=
editor:propdoc=RemotePath=For PUT.. this is the name of the file to be written.
editor:propdoc=RemotePath=
editor:propdoc=RemotePath=For GET.. the name of file(s) to retrieve.
editor:propdoc=RemotePath=Filenames of the form *.zip are allowed.
editor:propdoc=RemotePath=If you use * then the LocalPath should be a folder name, not a single file name.
end:FTP