# system.file.writeFile working from Script Console but not on button click

**URL:** <https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188>\
**Category:** Ignition\
**Tags:** scripting, ignition80, perspective\
**Created:** [September 29, 2020, 3:27pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188 "2020-09-29T15:27:26Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 3:27pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/1 "2020-09-29T15:27:27Z")

</div>

I have a weird issue I’ve been dealing with for the past couple days. I’m using a file upload component to upload a file onto a server (bypassing a horrible file upload interface in a web application). The filename is of this format:

`//SERVER-NAME/Path/filename.pdf`

where `filename.pdf` is the name of the uploaded file. The UNC path `//SERVER-NAME/Path` is added to the `ignition.conf` file.

I tried to run a simple script in the Script console to troubleshoot, but the file wrote successfully from the Script Console. Here is the sample script which worked correctly:

```auto
bytes = bytearray(b'HELLO WORLD')
filename = '//SERVER-NAME/Path/testdoc.pdf'
system.file.writeFile(filename, bytes)

```

I don’t know why a button press doesn’t yield the same result. When I log the exception that is thrown, it says

```auto
"File '//SERVER-NAME/Path/testdoc.pdf' doesn't exist or isn't a file"

```

What could be the problem?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 29, 2020, 4:29pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/2 "2020-09-29T16:29:26Z")

</div>

If it’s running on a _Perspective_ button the big difference is that when executed in the script console it’s running on your computer as your user in the Designer process, and when executed from a button press it’s executing on the gateway as whatever user the Ignition service uses.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 5:19pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/3 "2020-09-29T17:19:18Z")

</div>

So then the issue is likely how I [added a network path](https://docs.inductiveautomation.com/display/DOC80/Mapping+a+Network+Drive) to `ignition.conf`, right?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 29, 2020, 5:30pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/4 "2020-09-29T17:30:47Z")

</div>

Yes, probably something to do with that.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/5 "2020-09-29T19:53:47Z")

</div>

I’m looking in the `wrapper.log` file and I see the message

```auto
Unable to create path to file '//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/filename.pdf'

```

What does this error message mean?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 29, 2020, 8:00pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/6 "2020-09-29T20:00:23Z")

</div>

Seems like a permissions issue. Whoever is trying to write filename.pdf doesn’t have permissions on that network share to create the specified path.

```auto
//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/filename.pdf

```

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 8:11pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/7 "2020-09-29T20:11:14Z")

</div>

That isn’t necessarily true… End users don’t write to the share if they use a Perspective session (with a button and a file upload component). The server that hosts Ignition will write to the remote directory. I added authentication for the file share to the `ignition.conf` file and made sure the folder permissions were set correctly. I also made sure to share the directory with the user I added (and made sure the user / password combination was still valid).

That is what I understand from reading the docs, I may be incorrect.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 29, 2020, 8:21pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/8 "2020-09-29T20:21:16Z")

</div>

Maybe this doesn’t matter, but shouldn’t all those forward slashes be back slashes?

and what logger was responsible for that error message?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 29, 2020, 8:22pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/9 "2020-09-29T20:22:04Z")

</div>

> [@code\_skin](#):
>
> Whoever is trying to write filename.pdf doesn’t have permissions...

~~I'm referring to who is running Ignition Service on the Ignition server.~~

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c59e0c47ca27c306ddd85ad68228b55aa5b9ba42.png)

~~I think you have to make sure the Ignition Gateway server account has permissions to write to your network share.~~

EDIT:  
The above doesn't seem required.

You should be able to achieve the same with these configs:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/770d0bb2b94460249caeb36fb539994c14a0d4cb.png)

@paul-griffith; could you confirm this edit?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [September 29, 2020, 8:26pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/10 "2020-09-29T20:26:37Z")

</div>

> [@YF129701](#):
>
> So then the issue is likely how I [added a network path](https://docs.inductiveautomation.com/display/DOC80/Mapping+a+Network+Drive) to `ignition.conf` , right?

I assumed you added a network drive path as well? Do you get any print statements in the wrapper regarding a successfully mapped drive?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 29, 2020, 8:34pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/11 "2020-09-29T20:34:47Z")

</div>

> [@code\_skin](#):
>
> @paul-griffith; could you confirm this edit?

I'm pretty sure it's one or the other, yeah. For what it's worth, I've always had more success using the wrapper args approach - theoretically making the service run as a user should give it permissions, but I haven't had a lot of luck with that.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 9:41pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/12 "2020-09-29T21:41:58Z")

</div>

Here is the `ignition.conf` entry I added:

```auto
wrapper.share.2.location=\\10.1.20.11\Blinfo\Links
wrapper.share.2.target=P:
wrapper.share.2.type=DISK
wrapper.ntservice.account=<my_domain>\<username>
wrapper.ntservice.password=<my_password>
wrapper.share.2.account=<my_domain>\<username>
wrapper.share.2.password=<my_password>

```

Here is (essentially) how I use system.file.writeFile():

```auto
bytes = bytearray(b'HELLO WORLD') # bytes is an uploaded file
# Notice how REQUISITION_QUOTES is a subdirectory of `Blinfo/Links`
filename = '//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/<filename>'
# What else I tried
# filename = 'P:/REQUISITION_QUOTES/<filename>'
system.file.writeFile(filename, bytes)

```

Maybe it will serve me well to stop and start the Ignition service. As you can imagine, this isn’t the best option.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 29, 2020, 9:51pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/13 "2020-09-29T21:51:16Z")

</div>

If you never restarted it after adding those entries then there is no chance they will have been in effect.

Also consider the forward vs back slashes.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 9:57pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/14 "2020-09-29T21:57:40Z")

</div>

I did stop and start it before, but that was a while ago. Nothing has changed since then, but I might wait for a break to restart it.

Regarding the slashes, I use forward slashes singularly and if I use back slashes, they’re doubled up (because the first one escapes the character that follows it). I tried almost every combination.

Also, something I forgot to mention is that I can go to the Explorer on the Ignition server and I can put in `\\10.1.20.11\Blinfo\Links` and browse the folder. So it is reachable and the directory is shared.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [September 29, 2020, 10:34pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-working-from-script-console-but-not-on-button-click/39188/15 "2020-09-29T22:34:41Z")

</div>

Restarted the service and now working again… Thanks Kevin
