@yousolution/node-red-contrib-you-ftp-sftp 1.10.1 → 1.11.0
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/docker-compose.yml +22 -2
- package/nodes/ftp.js +71 -56
- package/nodes/ftps.js +4 -2
- package/package.json +12 -13
package/docker-compose.yml
CHANGED
|
@@ -10,8 +10,16 @@ services:
|
|
|
10
10
|
- ./data:/data
|
|
11
11
|
ports:
|
|
12
12
|
- '1880:1880'
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
# deploy:
|
|
15
|
+
# resources:
|
|
16
|
+
# limits:
|
|
17
|
+
# # cpus: 0.50
|
|
18
|
+
# memory: 45M
|
|
19
|
+
|
|
20
|
+
# environment:
|
|
21
|
+
# NODE_ENV: 'dev'
|
|
22
|
+
# NODE_OPTIONS: '--max-old-space-size=40'
|
|
15
23
|
|
|
16
24
|
ftps:
|
|
17
25
|
image: stilliard/pure-ftpd
|
|
@@ -32,3 +40,15 @@ services:
|
|
|
32
40
|
TLS_CN: 'localhost'
|
|
33
41
|
TLS_ORG: 'YourOrg'
|
|
34
42
|
TLS_C: 'DE'
|
|
43
|
+
|
|
44
|
+
# pure-ftpd:
|
|
45
|
+
# container_name: ftp
|
|
46
|
+
# image: stilliard/pure-ftpd
|
|
47
|
+
# ports:
|
|
48
|
+
# - 21:21
|
|
49
|
+
# - 30000-30009:30000-30009
|
|
50
|
+
# environment:
|
|
51
|
+
# PUBLICHOST: '0.0.0.0'
|
|
52
|
+
# FTP_USER_NAME: foo
|
|
53
|
+
# FTP_USER_PASS: pass
|
|
54
|
+
# FTP_USER_HOME: /home/foo
|
package/nodes/ftp.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
**/
|
|
16
16
|
|
|
17
|
+
const ftp = require('basic-ftp');
|
|
18
|
+
|
|
17
19
|
module.exports = function (RED) {
|
|
18
20
|
'use strict';
|
|
19
21
|
// var ftp = require('ftp');
|
|
@@ -50,11 +52,14 @@ module.exports = function (RED) {
|
|
|
50
52
|
this.workdir = n.workdir;
|
|
51
53
|
this.ftpConfig = RED.nodes.getNode(this.ftp);
|
|
52
54
|
|
|
55
|
+
const client = new ftp.Client();
|
|
56
|
+
|
|
53
57
|
if (this.ftpConfig) {
|
|
54
58
|
const node = this;
|
|
55
59
|
// console.log("FTP ftpConfig: " + JSON.stringify(this.ftpConfig));
|
|
56
|
-
node.on('input', (msg, send, done) => {
|
|
60
|
+
node.on('input', async (msg, send, done) => {
|
|
57
61
|
try {
|
|
62
|
+
// const client = new ftp.Client();
|
|
58
63
|
node.workdir = node.workdir || msg.workdir || './';
|
|
59
64
|
node.fileExtension = node.fileExtension || msg.fileExtension || '';
|
|
60
65
|
|
|
@@ -64,49 +69,59 @@ module.exports = function (RED) {
|
|
|
64
69
|
node.ftpConfig.options.user = msg.user || node.ftpConfig.options.user;
|
|
65
70
|
node.ftpConfig.options.password = msg.password || node.ftpConfig.options.password;
|
|
66
71
|
node.ftpConfig.options.pass = msg.pass || msg.password || node.ftpConfig.options.pass;
|
|
72
|
+
node.ftpConfig.options.secure = false;
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
try {
|
|
75
|
+
await client.access(node.ftpConfig.options);
|
|
76
|
+
// client.ftp.verbose = true;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
}
|
|
69
80
|
|
|
70
|
-
const
|
|
81
|
+
// const JSFtp = require('jsftp');
|
|
82
|
+
|
|
83
|
+
// const Ftp = new JSFtp(node.ftpConfig.options);
|
|
71
84
|
switch (node.operation) {
|
|
72
85
|
case 'list':
|
|
73
86
|
console.log('FTP List:' + node.workdir.toString());
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
try {
|
|
88
|
+
let data = await client.list(node.workdir);
|
|
76
89
|
msg.payload = data;
|
|
90
|
+
client.close();
|
|
77
91
|
node.send(msg);
|
|
78
|
-
})
|
|
92
|
+
} catch (err) {
|
|
93
|
+
client.close();
|
|
94
|
+
done(err);
|
|
95
|
+
}
|
|
79
96
|
break;
|
|
97
|
+
|
|
80
98
|
case 'get':
|
|
81
99
|
let ftpfilename = node.workdir + node.filename;
|
|
82
100
|
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
83
|
-
|
|
101
|
+
let str = '';
|
|
84
102
|
console.log('FTP Get:' + ftpfilename);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
socket.on('close', (err) => {
|
|
95
|
-
if (err) {
|
|
96
|
-
// node.error(err, msg);
|
|
97
|
-
done(err);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
node.status({});
|
|
101
|
-
msg.payload = {};
|
|
102
|
-
msg.payload.filedata = str;
|
|
103
|
-
msg.payload.filename = ftpfilename;
|
|
104
|
-
node.send(msg);
|
|
105
|
-
});
|
|
106
|
-
socket.resume();
|
|
107
|
-
}
|
|
103
|
+
|
|
104
|
+
const stream = require('stream');
|
|
105
|
+
const dataStream = new stream.Writable({
|
|
106
|
+
write: function (chunk, encoding, next) {
|
|
107
|
+
str += chunk.toString();
|
|
108
|
+
next();
|
|
109
|
+
},
|
|
108
110
|
});
|
|
111
|
+
try {
|
|
112
|
+
await client.downloadTo(dataStream, ftpfilename);
|
|
113
|
+
node.status({});
|
|
114
|
+
msg.payload = {};
|
|
115
|
+
msg.payload.filedata = str;
|
|
116
|
+
msg.payload.filename = ftpfilename;
|
|
117
|
+
client.close();
|
|
118
|
+
node.send(msg);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
client.close();
|
|
121
|
+
done(err);
|
|
122
|
+
}
|
|
109
123
|
break;
|
|
124
|
+
|
|
110
125
|
case 'put':
|
|
111
126
|
let newFile = '';
|
|
112
127
|
if (msg.payload.filename) {
|
|
@@ -126,39 +141,39 @@ module.exports = function (RED) {
|
|
|
126
141
|
|
|
127
142
|
console.log('FTP Put:' + newFile);
|
|
128
143
|
|
|
129
|
-
// let Ftp = new JSFtp(node.
|
|
130
|
-
|
|
131
|
-
const buffer = new Buffer(msgData);
|
|
144
|
+
// let Ftp = new JSFtp(node.ftpsConfig.options);
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
const { Readable } = require('stream');
|
|
147
|
+
const buffer = new Buffer.from(msgData);
|
|
148
|
+
try {
|
|
149
|
+
await client.uploadFrom(Readable.from(buffer), newFile);
|
|
150
|
+
node.status({});
|
|
151
|
+
msg.payload = {};
|
|
152
|
+
msg.payload.filename = newFile;
|
|
153
|
+
client.close();
|
|
154
|
+
node.send(msg);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
client.close();
|
|
157
|
+
done(err);
|
|
158
|
+
}
|
|
144
159
|
break;
|
|
160
|
+
|
|
145
161
|
case 'delete':
|
|
146
162
|
let delFile = '';
|
|
147
163
|
if (msg.payload.filename) delFile = msg.payload.filename;
|
|
148
164
|
else delFile = node.workdir + node.filename;
|
|
149
165
|
console.log('FTP Delete:' + delFile);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
166
|
+
try {
|
|
167
|
+
await client.remove(delFile);
|
|
168
|
+
node.status({});
|
|
169
|
+
msg.payload = {};
|
|
170
|
+
msg.payload.filename = delFile;
|
|
171
|
+
client.close();
|
|
172
|
+
node.send(msg);
|
|
173
|
+
} catch (err) {
|
|
174
|
+
client.close();
|
|
175
|
+
done(err);
|
|
176
|
+
}
|
|
162
177
|
break;
|
|
163
178
|
}
|
|
164
179
|
} catch (error) {
|
package/nodes/ftps.js
CHANGED
|
@@ -53,6 +53,8 @@ module.exports = function (RED) {
|
|
|
53
53
|
this.workdir = n.workdir;
|
|
54
54
|
this.ftpsConfig = RED.nodes.getNode(this.ftps);
|
|
55
55
|
|
|
56
|
+
const client = new ftps.Client();
|
|
57
|
+
|
|
56
58
|
if (this.ftpsConfig) {
|
|
57
59
|
const node = this;
|
|
58
60
|
// console.log("FTP ftpsConfig: " + JSON.stringify(this.ftpsConfig));
|
|
@@ -72,8 +74,7 @@ module.exports = function (RED) {
|
|
|
72
74
|
rejectUnauthorized: false,
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
client.ftp.verbose = true;
|
|
77
|
+
// client.ftp.verbose = true;
|
|
77
78
|
|
|
78
79
|
try {
|
|
79
80
|
await client.access(node.ftpsConfig.options);
|
|
@@ -93,6 +94,7 @@ module.exports = function (RED) {
|
|
|
93
94
|
let data = await client.list(node.workdir);
|
|
94
95
|
msg.payload = data;
|
|
95
96
|
client.close();
|
|
97
|
+
// client = null;
|
|
96
98
|
node.send(msg);
|
|
97
99
|
} catch (err) {
|
|
98
100
|
client.close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yousolution/node-red-contrib-you-ftp-sftp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
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": {
|
|
@@ -33,20 +33,19 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"ftp": "^0.3
|
|
37
|
-
"
|
|
38
|
-
"ssh2-sftp-client": "^9.0.4",
|
|
39
|
-
"basic-ftp": "^5.0.2"
|
|
36
|
+
"basic-ftp": "^5.0.3",
|
|
37
|
+
"ssh2-sftp-client": "^9.1.0"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
42
|
-
"@types/chai": "^4.3.
|
|
43
|
-
"@types/node-red
|
|
44
|
-
"@types/
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"node-red
|
|
40
|
+
"@types/chai": "^4.3.11",
|
|
41
|
+
"@types/node-red": "^1.3.4",
|
|
42
|
+
"@types/node-red-node-test-helper": "^0.3.3",
|
|
43
|
+
"@types/sinon": "^17.0.2",
|
|
44
|
+
"chai": "^4.3.10",
|
|
45
|
+
"mocha": "^10.0.2",
|
|
46
|
+
"node-red": "^3.1.0",
|
|
47
|
+
"node-red-node-test-helper": "^0.3.2",
|
|
49
48
|
"nyc": "^15.1.0",
|
|
50
|
-
"sinon": "^
|
|
49
|
+
"sinon": "^17.0.1"
|
|
51
50
|
}
|
|
52
51
|
}
|