FTP within a gateway script

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.

Can someone tell me what I am doing wrong?

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

That may be it. Let me check on that. Thanks for the info. I will let you know if that fixes the issue.

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

Hi Mark,

Maybe the connection is being closes somehow after it is initially opened.

Perhaps try calling and getting the return text from ftp.getwelcome() after opening the connection. See what it says.

When you are done with a connection are you calling ftp.quit() or ftp.close()?

Nick,

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.

Does it matter that I am executing this in a project script rather than a shared script?

No, shouldn’t matter, since you are giving the tag provider in the tag paths. Do you have any errors in the Gateway log or the wrapper.log file?

You can easily see what is in the wrapper.log file by installing and launching the WrapperLogViewer project. More info here: http://nickmudge.info/post/view-the-ignition-wrapper.log-file-in-the-designer-or-client

There are no errors in the wrapper log.

Are all the tags returning None? Can you read any tag value? Can you try to read a different tag value to see if it possible to read any tag at all?

They are all returning None.

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!!

Great! Yes a wrong path will have a None value. Glad you found the problem.

1 Like