I am trying to connect to one of our servers using FTP within a script running in the gateway. When I run through the script playground, it works fine, but running through the gateway script, it fails every time.
Here is the first few lines of code.
try:
ftp = FTP(toolsrv)
except Exception, err:
system.net.sendEmail(mailhost,fromaddress,'Cannot FTP to ' + str(rsc),'Unable to connect to ' + str(rsc) + ' via FTP to transfer the CPE recipe. Please contact APC Support to investigate. Reason: ' + str(err),1,emailaddresses)
return
# log into the tool with the creditials configured in tags.
try:
ftp.login(tooluser,toolpwd)
except Exception, err:
system.net.sendEmail(mailhost,fromaddress,'Cannot log into ' + str(rsc),'Unable to log into ' + str(rsc) + ' via FTP to transfer the CPE recipe. Please contact APC Support to investigate.\nFTP instance: ' + str(ftp) + '\nReason: ' + str(err),1,emailaddresses)
return
The line that is failing is the ftp.login(tooluser, toolpwd) line.
When the email is sent to me, this is the contents of the email. The reason at the end shows the error that I am getting.
Unable to log into ASML03 via FTP to transfer the CPE recipe. Please contact APC Support to investigate. Reason: ‘NoneType’ object has no attribute 'sendall’
I am using Ignition 7.8.5 in the linux environment.
You didn’t include the other code where it says credentials configured in tags,
but are you specifying the tag provider on those tags?
Gateway script tag references have to be provided the tag provider
I.E.
tooluser=system.tag.read("[default]PathToMyTag\tooluser").value
Still does not seem to work. Here is the entire code prior to the line where I am getting the error. I did confirm that the results of the tag reads is None. Does system.tag.readAll work in the gateway script environment?
tags = []
# Get FTP information from Tags
tags.append('[CPE]Conf/FTP Info/Tool User/' + str(rsc))
tags.append('[CPE]Conf/FTP Info/Tool Pwd/' + str(rsc))
tags.append('[CPE]Conf/FTP Info/Tool Server/' + str(rsc))
tags.append('[CPE]Conf/FTP Info/Tool Path/' + str(rsc))
# In the event of an error, get email information from the taqs
tags.append('[CPE]Conf/Email Parameters/Server')
tags.append('[CPE]Conf/Email Parameters/Email Addresses')
tags.append('[CPE]Conf/Email Parameters/From Address')
tags.append('[CPE]Conf/FTP Info/Temporary Path')
tagvals = system.tag.readAll(tags)
tooluser = tagvals[0].value
toolpwd = tagvals[1].value
toolsrv = tagvals[2].value
toolpath = tagvals[3].value
mailhost = tagvals[4].value
emailaddresses = tagvals[5].value.split(',')
fromaddress = tagvals[6].value
tmppath = tagvals[7].value
contents = open(filename, 'r')
# Open connection to the tool.
try:
ftp = FTP(toolsrv)
except Exception, err:
system.net.sendEmail(mailhost,fromaddress,'Cannot FTP to ' + str(rsc),'Unable to connect to ' + str(rsc) + ' via FTP to transfer the CPE recipe. Please contact APC Support to investigate. Reason: ' + str(err),1,emailaddresses)
return
# log into the tool with the creditials configured in tags.
try:
ftp.login(tooluser,toolpwd)
except Exception, err:
system.net.sendEmail(mailhost,fromaddress,'Cannot log into ' + str(rsc),'Unable to log into ' + str(rsc) + ' via FTP to transfer the CPE recipe using ' + str(toolsrv) + ' and ' + str(tooluser) + '. Please contact APC Support to investigate.\nFTP instance: ' + str(ftp) + '\nReason: ' + str(err),1,emailaddresses)
return
Yes, I am calling ftp.quit() at the end of the script. For some reason, the tag reads are not returning the values. I have tried using the system.tag.readAll() and the system.tag.read() script and both fail to return values for the tags.
Actually, it is only the ones that refer to the rsc variable that are missing data. I found out that there must have been some white space in the variable. Once I performed the strip, it works now. Thank you for your help!!