# FTP within a gateway script

**URL:** <https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810>\
**Category:** Ignition\
**Created:** [July 17, 2017, 10:42pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810 "2017-07-17T22:42:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 17, 2017, 10:42pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/1 "2017-07-17T22:42:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 18, 2017, 2:30pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/2 "2017-07-18T14:30:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 2:32pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/3 "2017-07-18T14:32:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 3:05pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/4 "2017-07-18T15:05:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 18, 2017, 4:15pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/5 "2017-07-18T16:15:01Z")

</div>

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()?

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 4:34pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/6 "2017-07-18T16:34:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 4:35pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/7 "2017-07-18T16:35:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 18, 2017, 4:40pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/8 "2017-07-18T16:40:05Z")

</div>

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](http://nickmudge.info/post/view-the-ignition-wrapper.log-file-in-the-designer-or-client)

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 4:48pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/9 "2017-07-18T16:48:27Z")

</div>

There are no errors in the wrapper log.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 18, 2017, 7:13pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/10 "2017-07-18T19:13:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 18, 2017, 9:59pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/11 "2017-07-18T21:59:01Z")

</div>

They are all returning None.

---

<div class="post-metadata">

**Author:** ![mluedecke](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mluedecke](https://forum.inductiveautomation.com/u/mluedecke)\
**Post date:** [July 19, 2017, 5:00pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/12 "2017-07-19T17:00:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 19, 2017, 5:02pm UTC](https://forum.inductiveautomation.com/t/ftp-within-a-gateway-script/14810/13 "2017-07-19T17:02:46Z")

</div>

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