@yousolution/node-red-contrib-you-ftp-sftp 1.8.9 → 1.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/nodes/ftp.js +16 -17
- package/nodes/sftp.js +20 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
# @yousolution/node-red-contrib-you-ftp-sftp
|
|
2
2
|
|
|
3
|
-
A Node-RED node to FTP and SFTP Client (
|
|
3
|
+
A Node-RED node to FTP and SFTP Client (_fork node-red-contrib-ftp-sftp_).
|
|
4
|
+
|
|
5
|
+
**Adds FTP/SFTP error handling**
|
|
6
|
+
|
|
7
|
+
Please log issues in the repo for assistance.
|
|
4
8
|
(https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git)
|
|
5
9
|
|
|
6
10
|
## Install
|
|
7
11
|
|
|
8
12
|
Run the following command in the root directory of your Node-RED install
|
|
9
13
|
|
|
10
|
-
npm install node-red-contrib-ftp-sftp
|
|
14
|
+
npm install @yousolution/node-red-contrib-you-ftp-sftp
|
|
11
15
|
|
|
12
16
|
## Configuration
|
|
13
17
|
|
package/nodes/ftp.js
CHANGED
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
|
|
17
17
|
module.exports = function (RED) {
|
|
18
18
|
'use strict';
|
|
19
|
-
var ftp = require('ftp');
|
|
20
|
-
var fs = require('fs');
|
|
19
|
+
// var ftp = require('ftp');
|
|
20
|
+
// var fs = require('fs');
|
|
21
21
|
|
|
22
|
-
const ReadableStream = require('stream');
|
|
22
|
+
// const ReadableStream = require('stream');
|
|
23
23
|
|
|
24
24
|
function FtpNode(n) {
|
|
25
25
|
RED.nodes.createNode(this, n);
|
|
26
|
-
|
|
26
|
+
// let node = this;
|
|
27
27
|
|
|
28
28
|
this.options = {
|
|
29
29
|
host: n.host || 'localhost',
|
|
@@ -51,7 +51,7 @@ module.exports = function (RED) {
|
|
|
51
51
|
this.ftpConfig = RED.nodes.getNode(this.ftp);
|
|
52
52
|
|
|
53
53
|
if (this.ftpConfig) {
|
|
54
|
-
|
|
54
|
+
const node = this;
|
|
55
55
|
// console.log("FTP ftpConfig: " + JSON.stringify(this.ftpConfig));
|
|
56
56
|
node.on('input', (msg, send, done) => {
|
|
57
57
|
try {
|
|
@@ -65,11 +65,11 @@ module.exports = function (RED) {
|
|
|
65
65
|
node.ftpConfig.options.password = msg.password || node.ftpConfig.options.password;
|
|
66
66
|
node.ftpConfig.options.pass = msg.pass || msg.password || node.ftpConfig.options.pass;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const JSFtp = require('jsftp');
|
|
69
69
|
|
|
70
|
+
const Ftp = new JSFtp(node.ftpConfig.options);
|
|
70
71
|
switch (node.operation) {
|
|
71
72
|
case 'list':
|
|
72
|
-
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
73
73
|
console.log('FTP List:' + node.workdir.toString());
|
|
74
74
|
Ftp.ls(node.workdir, (err, data) => {
|
|
75
75
|
// console.log(data);
|
|
@@ -78,8 +78,7 @@ module.exports = function (RED) {
|
|
|
78
78
|
});
|
|
79
79
|
break;
|
|
80
80
|
case 'get':
|
|
81
|
-
|
|
82
|
-
var ftpfilename = node.workdir + node.filename;
|
|
81
|
+
const ftpfilename = node.workdir + node.filename;
|
|
83
82
|
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
84
83
|
var str = '';
|
|
85
84
|
console.log('FTP Get:' + ftpfilename);
|
|
@@ -109,27 +108,27 @@ module.exports = function (RED) {
|
|
|
109
108
|
});
|
|
110
109
|
break;
|
|
111
110
|
case 'put':
|
|
112
|
-
|
|
111
|
+
let newFile = '';
|
|
113
112
|
if (msg.payload.filename) {
|
|
114
113
|
newFile = msg.payload.filename;
|
|
115
114
|
} else if (node.filename == '') {
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
let d = new Date();
|
|
116
|
+
let guid = d.getTime().toString();
|
|
118
117
|
if (node.fileExtension == '') node.fileExtension = '.txt';
|
|
119
118
|
newFile = node.workdir + guid + node.fileExtension;
|
|
120
119
|
} else {
|
|
121
120
|
newFile = node.workdir + node.filename;
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
let msgData = '';
|
|
125
124
|
if (msg.payload.filedata) msgData = msg.payload.filedata;
|
|
126
125
|
else msgData = JSON.stringify(msg.payload);
|
|
127
126
|
|
|
128
127
|
console.log('FTP Put:' + newFile);
|
|
129
128
|
|
|
130
|
-
|
|
129
|
+
// let Ftp = new JSFtp(node.ftpConfig.options);
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
const buffer = new Buffer(msgData);
|
|
133
132
|
|
|
134
133
|
Ftp.put(buffer, newFile, (err) => {
|
|
135
134
|
if (err) {
|
|
@@ -144,11 +143,11 @@ module.exports = function (RED) {
|
|
|
144
143
|
});
|
|
145
144
|
break;
|
|
146
145
|
case 'delete':
|
|
147
|
-
|
|
146
|
+
let delFile = '';
|
|
148
147
|
if (msg.payload.filename) delFile = msg.payload.filename;
|
|
149
148
|
else delFile = node.workdir + node.filename;
|
|
150
149
|
console.log('FTP Delete:' + delFile);
|
|
151
|
-
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
150
|
+
// var Ftp = new JSFtp(node.ftpConfig.options);
|
|
152
151
|
Ftp.raw('dele', delFile, (err, data) => {
|
|
153
152
|
if (err) {
|
|
154
153
|
// node.error(err, msg);
|
package/nodes/sftp.js
CHANGED
|
@@ -33,18 +33,18 @@ const fs = require('fs');
|
|
|
33
33
|
module.exports = function (RED) {
|
|
34
34
|
'use strict';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const sftp = require('ssh2').Client;
|
|
37
|
+
const fs = require('fs');
|
|
38
38
|
|
|
39
39
|
function SFtpNode(n) {
|
|
40
40
|
RED.nodes.createNode(this, n);
|
|
41
|
-
var node = this;
|
|
41
|
+
// var node = this;
|
|
42
42
|
|
|
43
43
|
console.log('SFTP - Config - hmac: ' + n.hmac);
|
|
44
44
|
console.log('SFTP - Config - cipher: ' + n.cipher);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let keyFile = null;
|
|
47
|
+
let keyData = null;
|
|
48
48
|
if (process.env.SFTP_SSH_KEY_FILE) {
|
|
49
49
|
keyFile = process.env.SFTP_SSH_KEY_FILE;
|
|
50
50
|
keyFile = require('path').resolve(__dirname, '../../' + keyFile);
|
|
@@ -103,7 +103,7 @@ module.exports = function (RED) {
|
|
|
103
103
|
this.sftpConfig = RED.nodes.getNode(this.sftp);
|
|
104
104
|
|
|
105
105
|
if (this.sftpConfig) {
|
|
106
|
-
|
|
106
|
+
const node = this;
|
|
107
107
|
node.on('input', function (msg, send, done) {
|
|
108
108
|
try {
|
|
109
109
|
node.workdir = node.workdir || msg.workdir || './';
|
|
@@ -115,7 +115,7 @@ module.exports = function (RED) {
|
|
|
115
115
|
node.sftpConfig.options.username = msg.user || node.sftpConfig.options.username || '';
|
|
116
116
|
node.sftpConfig.options.password = msg.password || node.sftpConfig.options.password || '';
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
let conn = new sftp();
|
|
119
119
|
|
|
120
120
|
this.sendMsg = function (err, result) {
|
|
121
121
|
if (err) {
|
|
@@ -149,18 +149,18 @@ module.exports = function (RED) {
|
|
|
149
149
|
done(err);
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
let ftpfilename = node.workdir + node.filename;
|
|
153
153
|
|
|
154
154
|
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
let bufferarray = [];
|
|
157
157
|
|
|
158
158
|
// Be very careful bufferSize too large causes issues with multi threading
|
|
159
|
-
|
|
159
|
+
let stream = sftp.createReadStream(ftpfilename, { highWaterMark: 1024, bufferSize: 1024 });
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
let counter = 0;
|
|
162
|
+
let buf = '';
|
|
163
|
+
let byteSize = 65536;
|
|
164
164
|
|
|
165
165
|
stream
|
|
166
166
|
.on('data', function (d) {
|
|
@@ -186,24 +186,24 @@ module.exports = function (RED) {
|
|
|
186
186
|
done(err);
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
|
-
|
|
189
|
+
let newFile = '';
|
|
190
190
|
if (msg.payload.filename) {
|
|
191
191
|
newFile = msg.payload.filename;
|
|
192
192
|
} else if (node.filename == '') {
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
let d = new Date();
|
|
194
|
+
let guid = d.getTime().toString();
|
|
195
195
|
if (node.fileExtension == '') node.fileExtension = '.txt';
|
|
196
196
|
newFile = node.workdir + guid + node.fileExtension;
|
|
197
197
|
} else {
|
|
198
198
|
newFile = node.workdir + node.filename;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
let msgData = '';
|
|
202
202
|
if (msg.payload.filedata) msgData = msg.payload.filedata;
|
|
203
203
|
else msgData = JSON.stringify(msg.payload);
|
|
204
204
|
|
|
205
205
|
console.log('SFTP Put:' + newFile);
|
|
206
|
-
|
|
206
|
+
let writeStream = sftp.createWriteStream(newFile, { flags: 'w' });
|
|
207
207
|
// var payloadBuff = new Buffer(msgData);
|
|
208
208
|
// writeStream.write(payloadBuff, node.sendMsg);
|
|
209
209
|
writeStream.write(msgData, function (err, result) {
|
|
@@ -222,7 +222,7 @@ module.exports = function (RED) {
|
|
|
222
222
|
done(err);
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
let ftpfilename = node.workdir + node.filename;
|
|
226
226
|
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
227
227
|
console.log('SFTP Deleting File: ' + ftpfilename);
|
|
228
228
|
sftp.unlink(ftpfilename, function (err) {
|
|
@@ -257,6 +257,7 @@ module.exports = function (RED) {
|
|
|
257
257
|
});
|
|
258
258
|
} else {
|
|
259
259
|
this.error('missing sftp configuration');
|
|
260
|
+
done(this.error);
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
263
|
RED.nodes.registerType('sftp in', SFtpInNode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yousolution/node-red-contrib-you-ftp-sftp",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.11",
|
|
4
4
|
"description": "A node-red node that support FTP and SFTP file transfer using $() environment variables to control the ftp connection details",
|
|
5
5
|
"main": "sftp.js",
|
|
6
6
|
"scripts": {
|