How can I send CSV files to an FTP server?

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?

[{"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":""}]

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

Error

[{"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":""}]

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?

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.

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

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

I have tried both and it has not worked

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

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

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