# Not able to write file content into SFTP folder

**URL:** <https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682>\
**Category:** General\
**Created:** [2 April 2022 12:15 UTC](https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682 "2022-04-02T12:15:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinmeera](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sinmeera](https://discourse.nodered.org/u/sinmeera)\
**Post date:** [2 April 2022 12:15 UTC](https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682/1 "2022-04-02T12:15:16Z")

</div>

HI All,

I have installed "node-red-contrib-better-sftp" into my node red and using this am trying to create the file with the content into the SFTP folder.  
Issue : i have done the configuration and able to create a file into my specified folder but it is a empty is getting created.  
Please suggest/guide me if i am missing anything on this code.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9a8d8ddf7f495a13a2f6297351280ba8dc28a05f.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78e85a896688fb75f9cacdafdbf430751798cb1c.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d03ba82ba64713571a6da153809dd04be6f5382f.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/422adb60d4b8bd912fda696756c80106578906f7.png)

Here all the files created 0 KB with no content.

Please help me to resolve this problem

Library downloaded from : [node-red-contrib-better-sftp (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-better-sftp).

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [3 April 2022 08:51 UTC](https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682/2 "2022-04-03T08:51:34Z")

</div>

I think the important point is that if `msg.payload.data` is a string it will be considered to be a path to a **local** file, where local means on the machine running the Node-RED backend.

So in this case the node will look for the file `./data/testfile/SAMPLE.txt`. That is a relative path which may also be a problem as I can never remember without testing if this ends up being relative to the directory Node-RED was started from or somewhere else.

If you just want to write a string to the file then it needs to be converted to a buffer first.

```auto
msg.payload.data = Buffer.from("some string", "utf-8");

```

---

<div class="post-metadata">

**Author:** ![sinmeera](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@sinmeera](https://discourse.nodered.org/u/sinmeera)\
**Post date:** [4 April 2022 07:34 UTC](https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682/3 "2022-04-04T07:34:26Z")

</div>

> [@hardillb](#):
>
> `msg.payload.data = Buffer.from("some string", "utf-8");`

Thank You very much Hardilib. Your solutions worked for me. Now i am able to write data into the file in SFTP.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 April 2022 07:34 UTC](https://discourse.nodered.org/t/not-able-to-write-file-content-into-sftp-folder/60682/4 "2022-04-18T07:34:53Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
