# How can I send CSV files to an FTP server?

**URL:** <https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200>\
**Category:** General\
**Created:** [15 January 2021 21:20 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200 "2021-01-15T21:20:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [15 January 2021 21:20 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/1 "2021-01-15T21:20:32Z")

</div>

Hello,  
I would like to send csv files to an FTP server. Node-Red is running on a Windows PC. How can I send the locale file to the FTP server with PUT? I want to add a current date before I send the file. How can I do this?

```auto
[{"id":"6aa857af.f6ab68","type":"debug","z":"94605fc7.4bb39","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":240,"wires":[]},{"id":"e1b2583f.12abf8","type":"inject","z":"94605fc7.4bb39","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"str","x":260,"y":240,"wires":[["e5794edc.e090a"]]},{"id":"e5794edc.e090a","type":"function","z":"94605fc7.4bb39","name":"","func":"//???\nmsg.localFilename;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":240,"wires":[["8240390d.941b28"]]},{"id":"8240390d.941b28","type":"ftp in","z":"94605fc7.4bb39","ftp":"c509b3c8.3d2ab","operation":"put","filename":"","localFilename":"","name":"","x":570,"y":240,"wires":[["6aa857af.f6ab68"]]},{"id":"d8a1317f.5848f","type":"file","z":"94605fc7.4bb39","name":"","filename":"E:\\NEU.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf-16be","x":490,"y":180,"wires":[[]]},{"id":"c509b3c8.3d2ab","type":"ftp","host":"192.168.178.47","port":"21","secureOptions":"","user":"tatest","connTimeout":"","pasvTimeout":"","keepalive":""}]

```

---

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [16 January 2021 17:15 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/2 "2021-01-16T17:15:26Z")

</div>

I tried again but I always get the error message "Invalid File".

![Error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9e6d3c3b8b9a4ee21f0c6aa2e5138b405eb56c30.jpeg)

```auto
[{"id":"91039113.5ae0b8","type":"debug","z":"95c84ff6.b3002","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":2260,"wires":[]},{"id":"ebf6cb8.83c77b8","type":"inject","z":"95c84ff6.b3002","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":280,"y":2300,"wires":[["908d94cd.cd4578"]]},{"id":"90bb94be.009978","type":"ftp in","z":"95c84ff6.b3002","ftp":"c509b3c8.3d2ab","operation":"put","filename":"","localFilename":"","name":"","x":950,"y":2280,"wires":[["91039113.5ae0b8"]]},{"id":"773409cc.e68b38","type":"function","z":"95c84ff6.b3002","name":"Generate File to send","func":"var msg1 = msg.payload;\nvar date;\ndate = new Date();\ndate = (date.getFullYear() + '' + ('00' + (date.getMonth()+1)).slice(-2) + '' + ('00' + date.getDate()).slice(-2) + '_' + ('00' + date.getHours()).slice(-2) + '' + ('00' + date.getMinutes()).slice(-2) + '' + ('00' + date.getSeconds()).slice(-2));\n//msg.payload = {};\n//ftp server \nmsg.payload.filename=\"C:/Users/Frank/Downloads/\"+date+\"data.csv\";// ftp Folder from File Zilla\nmsg.payload.filedata= msg1; // Needs to be a string\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":2300,"wires":[["90bb94be.009978"]]},{"id":"908d94cd.cd4578","type":"file in","z":"95c84ff6.b3002","name":"","filename":"E:\\NEU.csv","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":470,"y":2300,"wires":[["773409cc.e68b38"]]},{"id":"c509b3c8.3d2ab","type":"ftp","host":"192.168.178.47","port":"21","secureOptions":"","user":"tatest","connTimeout":"","pasvTimeout":"","keepalive":""}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 January 2021 20:19 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/3 "2021-01-16T20:19:03Z")

</div>

In your debug message you will see the node id producing the error. Copy it and in the editor do a `find` (ctrl-f on a mac) and it will show the node involved. I assume it is the `file-in` node.

Does Node-RED have access to that file on that drive?  
Is Node-RED running on a device that has access to that file?

---

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [16 January 2021 20:56 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/4 "2021-01-16T20:56:49Z")

</div>

Hello,  
Node-Red has access to the file I want to send, I can also send it by e-mail - I have already tested this.

I also have access to the files from the FTP server. If I activate "List" I can also see which files are on the FTP server.(see picture) As soon as I activate Put and want to send the file, the error Invalid Filename always appears.

Can it be that you have to write a different file path in the function because Node-Red runs on Windows?

I want to send a file from the path E:\NEU.csv where Node-Red is also running to C:/Users/Frank/Downloads -\> I have specified this path as FTP folder in File Zilla.  
The FTP server runs on another Windows computer that is in the same network.

 ![FTP Server access List](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/3524bc800c485c027e59ad6aeb0c67709fac87d3.jpeg)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 January 2021 21:18 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/5 "2021-01-16T21:18:57Z")

</div>

Yes you may need to escape the \ so e:\ENU. Or use e:/ENU

---

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [16 January 2021 21:23 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/6 "2021-01-16T21:23:23Z")

</div>

Do I have to do this with the "file in node" and with the generated file in the function?

---

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [16 January 2021 21:40 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/7 "2021-01-16T21:40:04Z")

</div>

I have tried both and it has not worked

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 January 2021 02:23 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/8 "2021-01-17T02:23:45Z")

</div>

> # ftp in
> 
> Allows LIST, GET, PUT and DELETE of files on a remote FTP server.
> 
> ### Inputs
> 
> `filename` string  
> the path/name of the file on the remote FTP server.
> 
> `localFilename` string  
> the path/name of the file on the local machine.

You need to set `msg.filename` and `msg.localFilename` in the function node, not `msg.payload.filename` and `msg.payload.localFilename`

---

<div class="post-metadata">

**Author:** ![robo7795](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@robo7795](https://discourse.nodered.org/u/robo7795)\
**Post date:** [17 January 2021 12:59 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/9 "2021-01-17T12:59:58Z")

</div>

Yes you are right I must set msg.filename and msg.localFilename

---

<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:** [31 January 2021 13:00 UTC](https://discourse.nodered.org/t/how-can-i-send-csv-files-to-an-ftp-server/39200/10 "2021-01-31T13:00:01Z")

</div>

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