@yousolution/node-red-contrib-you-ftp-sftp 1.9.2 → 1.10.1
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 +1 -1
- package/history.md +4 -0
- package/nodes/sftp.html +64 -29
- package/nodes/sftp.js +239 -141
- package/package.json +2 -2
package/docker-compose.yml
CHANGED
package/history.md
ADDED
package/nodes/sftp.html
CHANGED
|
@@ -29,6 +29,18 @@
|
|
|
29
29
|
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
|
|
30
30
|
<input type="password" id="node-config-input-password">
|
|
31
31
|
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-config-input-ssh-key-in"><i class="fa fa-lock"></i> SSH-Key file</label>
|
|
34
|
+
<input type="file" id="node-config-input-ssh-key-in">
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-config-input-selected-sshkey"><i class="fa fa-lock"></i> Selected SSH-Key file </label>
|
|
38
|
+
<input type="checkbox" disabled id="node-config-input-selected-sshkey">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<!-- <label for="node-config-input-sshkey"><i class="fa fa-lock"></i> SSH-Key</label> -->
|
|
42
|
+
<textarea id="node-config-input-sshkey" style="display:none;"> </textarea>
|
|
43
|
+
</div>
|
|
32
44
|
<div class="form-row">
|
|
33
45
|
<label for="node-config-input-hmac"><i class="fa fa-wrench"></i>hmac</label>
|
|
34
46
|
<select multiple type="text" id="node-config-input-hmac" size="9">
|
|
@@ -69,18 +81,41 @@
|
|
|
69
81
|
<script type="text/javascript">
|
|
70
82
|
RED.nodes.registerType('sftp', {
|
|
71
83
|
category: 'config',
|
|
72
|
-
color:
|
|
84
|
+
color: 'BurlyWood',
|
|
73
85
|
defaults: {
|
|
74
86
|
host: { value: 'localhost' },
|
|
75
87
|
port: { value: '22' },
|
|
76
88
|
username: { value: '', required: true },
|
|
77
|
-
password: { value: ''
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
password: { value: '' },
|
|
90
|
+
sshkey: { value: '' },
|
|
91
|
+
hmac: { value: 'hmac-sha2-256,hmac-sha2-512,hmac-sha1', required: true },
|
|
92
|
+
cipher: { value: 'aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm', required: true },
|
|
93
|
+
},
|
|
94
|
+
label: function () {
|
|
95
|
+
return this.host;
|
|
96
|
+
},
|
|
97
|
+
oneditprepare: function () {
|
|
98
|
+
const sshKeyFileIn = document.getElementById('node-config-input-ssh-key-in');
|
|
99
|
+
const sshKeyFile = document.getElementById('node-config-input-sshkey');
|
|
100
|
+
|
|
101
|
+
if (document.getElementById('node-config-input-sshkey').value) {
|
|
102
|
+
$('#node-config-input-selected-sshkey').prop('checked', true);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// node-config-input-selected-sshkey
|
|
106
|
+
|
|
107
|
+
// let fileOutput = document.getElementById("fileOutput");
|
|
108
|
+
sshKeyFileIn.addEventListener('change', function () {
|
|
109
|
+
const fileReader = new FileReader();
|
|
110
|
+
fileReader.onload = function () {
|
|
111
|
+
// console.log(fileReader.result);
|
|
112
|
+
sshKeyFile.value = fileReader.result;
|
|
113
|
+
};
|
|
114
|
+
// console.log({ type: this.files[0].type });
|
|
115
|
+
// console.log({ size: this.files[0].size });
|
|
116
|
+
fileReader.readAsBinaryString(this.files[0]);
|
|
117
|
+
});
|
|
80
118
|
},
|
|
81
|
-
label: function() {
|
|
82
|
-
return this.host
|
|
83
|
-
}
|
|
84
119
|
});
|
|
85
120
|
</script>
|
|
86
121
|
|
|
@@ -129,23 +164,23 @@
|
|
|
129
164
|
</script>
|
|
130
165
|
|
|
131
166
|
<script type="text/x-red" data-help-name="sftp in">
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
<h1>SFTP Client</h1>
|
|
168
|
+
<p>
|
|
169
|
+
<b>Node config:</b>
|
|
170
|
+
process.env.<b>SFTP_SSH_KEY_FILE</b> - If you want to use private SSH key set this environment variable
|
|
171
|
+
<ul>
|
|
172
|
+
<li><b>PUT</b> - Set <code>msg.payload.filedata</code> to the file contents you want pushed and will be uploaded to {GUID}.FileExtension. If you need more changes file request to github.</li>
|
|
173
|
+
<li><b>GET</b> - Set <code>msg.payload.filename</code> to get the file or will use Workdir + Filename in configuration. Leave configuration blank to set in code.</li>
|
|
174
|
+
<li><b>DELETE</b> - Set <code>msg.payload.filename</code> to delete the file or will use Workdir + Filename in configuration. Leave configuration blank to set in code.</li>
|
|
175
|
+
<li><b>LIST</b> - Uses the workdir</li>
|
|
176
|
+
</ul>
|
|
177
|
+
</p>
|
|
143
178
|
</script>
|
|
144
179
|
|
|
145
180
|
<script type="text/javascript">
|
|
146
181
|
RED.nodes.registerType('sftp in', {
|
|
147
182
|
category: 'storage-input',
|
|
148
|
-
color:
|
|
183
|
+
color: 'BurlyWood',
|
|
149
184
|
defaults: {
|
|
150
185
|
sftp: { type: 'sftp', required: true },
|
|
151
186
|
operation: { value: 'list', required: true },
|
|
@@ -155,11 +190,11 @@
|
|
|
155
190
|
fileExtension: { value: '.txt' },
|
|
156
191
|
workdir: { value: '' },
|
|
157
192
|
savedir: { value: '' },
|
|
158
|
-
name: { value: '' }
|
|
193
|
+
name: { value: '' },
|
|
159
194
|
},
|
|
160
195
|
inputs: 1,
|
|
161
196
|
outputs: 1,
|
|
162
|
-
icon:
|
|
197
|
+
icon: 'file.png',
|
|
163
198
|
label: function () {
|
|
164
199
|
var sftpNode = RED.nodes.node(this.sftp);
|
|
165
200
|
return this.name || 'sftp';
|
|
@@ -168,11 +203,11 @@
|
|
|
168
203
|
return this.name ? 'node_label_italic' : '';
|
|
169
204
|
},
|
|
170
205
|
oneditprepare: function () {
|
|
171
|
-
var filename = $(
|
|
172
|
-
var fileContents = $(
|
|
173
|
-
var fileExtension = $(
|
|
174
|
-
$(
|
|
175
|
-
var id = $(
|
|
206
|
+
var filename = $('.input-filename-row');
|
|
207
|
+
var fileContents = $('.input-fileContents-row');
|
|
208
|
+
var fileExtension = $('.input-fileExtension-row');
|
|
209
|
+
$('#node-input-operation').change(function () {
|
|
210
|
+
var id = $('#node-input-operation option:selected').val();
|
|
176
211
|
console.log(id);
|
|
177
212
|
if (id == 'list') {
|
|
178
213
|
filename.hide();
|
|
@@ -181,10 +216,10 @@
|
|
|
181
216
|
filename.show();
|
|
182
217
|
fileContents.hide();
|
|
183
218
|
fileExtension.show();
|
|
184
|
-
} else if (id =='get') {
|
|
219
|
+
} else if (id == 'get') {
|
|
185
220
|
filename.show();
|
|
186
221
|
fileExtension.hide();
|
|
187
|
-
} else if (id =='delete') {
|
|
222
|
+
} else if (id == 'delete') {
|
|
188
223
|
filename.show();
|
|
189
224
|
fileExtension.hide();
|
|
190
225
|
} else {
|
|
@@ -192,6 +227,6 @@
|
|
|
192
227
|
fileExtension.hide();
|
|
193
228
|
}
|
|
194
229
|
});
|
|
195
|
-
}
|
|
230
|
+
},
|
|
196
231
|
});
|
|
197
232
|
</script>
|
package/nodes/sftp.js
CHANGED
|
@@ -28,23 +28,31 @@ TODO
|
|
|
28
28
|
|
|
29
29
|
// STILL VALIDATING CONNECTIVITY
|
|
30
30
|
// -- DID validate it works with list/dir
|
|
31
|
-
const fs = require('fs');
|
|
31
|
+
// const fs = require('fs');
|
|
32
32
|
|
|
33
33
|
module.exports = function (RED) {
|
|
34
34
|
'use strict';
|
|
35
35
|
|
|
36
|
-
const sftp = require('ssh2').Client;
|
|
36
|
+
// const sftp = require('ssh2').Client;
|
|
37
37
|
const fs = require('fs');
|
|
38
38
|
|
|
39
39
|
function SFtpNode(n) {
|
|
40
40
|
RED.nodes.createNode(this, n);
|
|
41
41
|
// var node = this;
|
|
42
42
|
|
|
43
|
-
console.log('SFTP - Config -
|
|
44
|
-
console.log('SFTP - Config -
|
|
43
|
+
// console.log('SFTP - Config - username: ' + n.username);
|
|
44
|
+
// console.log('SFTP - Config - hmac: ' + n.hmac);
|
|
45
|
+
// console.log('SFTP - Config - cipher: ' + n.cipher);
|
|
46
|
+
|
|
47
|
+
// console.log('SFTP - Config - ssh-key: ' + n.sshkey);
|
|
45
48
|
|
|
46
49
|
let keyFile = null;
|
|
47
50
|
let keyData = null;
|
|
51
|
+
|
|
52
|
+
if (n.sshkey) {
|
|
53
|
+
keyFile = 'keyFile';
|
|
54
|
+
keyData = n.sshkey;
|
|
55
|
+
}
|
|
48
56
|
if (process.env.SFTP_SSH_KEY_FILE) {
|
|
49
57
|
keyFile = process.env.SFTP_SSH_KEY_FILE;
|
|
50
58
|
keyFile = require('path').resolve(__dirname, '../../' + keyFile);
|
|
@@ -60,7 +68,11 @@ module.exports = function (RED) {
|
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
if (keyFile && keyData) {
|
|
63
|
-
console.log('SFTP - Using
|
|
71
|
+
console.log('SFTP - Using key file');
|
|
72
|
+
// console.log('*******************');
|
|
73
|
+
// console.log('SFTP - Username: ' + n.username);
|
|
74
|
+
// console.log('SFTP - Using privateKey: ' + keyFile + ' Length: ' + keyData.toString().length);
|
|
75
|
+
// console.log('*******************');
|
|
64
76
|
this.options = {
|
|
65
77
|
host: n.host || 'localhost',
|
|
66
78
|
port: n.port || 21,
|
|
@@ -68,24 +80,139 @@ module.exports = function (RED) {
|
|
|
68
80
|
password: n.password,
|
|
69
81
|
privateKey: keyData,
|
|
70
82
|
algorithms: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
kex: [
|
|
84
|
+
'curve25519-sha256',
|
|
85
|
+
'curve25519-sha256@libssh.org',
|
|
86
|
+
'ecdh-sha2-nistp256',
|
|
87
|
+
'ecdh-sha2-nistp384',
|
|
88
|
+
'ecdh-sha2-nistp521',
|
|
89
|
+
'diffie-hellman-group-exchange-sha256',
|
|
90
|
+
'diffie-hellman-group14-sha256',
|
|
91
|
+
'diffie-hellman-group15-sha512',
|
|
92
|
+
'diffie-hellman-group16-sha512',
|
|
93
|
+
'diffie-hellman-group17-sha512',
|
|
94
|
+
'diffie-hellman-group18-sha512',
|
|
95
|
+
'diffie-hellman-group-exchange-sha1',
|
|
96
|
+
'diffie-hellman-group14-sha1',
|
|
97
|
+
'diffie-hellman-group1-sha1',
|
|
98
|
+
],
|
|
99
|
+
cipher: [
|
|
100
|
+
'chacha20-poly1305@openssh.com',
|
|
101
|
+
'aes128-gcm',
|
|
102
|
+
'aes128-gcm@openssh.com',
|
|
103
|
+
'aes256-gcm',
|
|
104
|
+
'aes256-gcm@openssh.com',
|
|
105
|
+
'aes128-ctr',
|
|
106
|
+
'aes192-ctr',
|
|
107
|
+
'aes256-ctr',
|
|
108
|
+
'3des-cbc',
|
|
109
|
+
'aes256-cbc',
|
|
110
|
+
'aes192-cbc',
|
|
111
|
+
'aes128-cbc',
|
|
112
|
+
// 'arcfour256',
|
|
113
|
+
// 'arcfour128',
|
|
114
|
+
// 'arcfour',
|
|
115
|
+
// 'blowfish-cbc',
|
|
116
|
+
// 'ast128-cbc',
|
|
117
|
+
],
|
|
118
|
+
serverHostKey: [
|
|
119
|
+
'ssh-ed25519',
|
|
120
|
+
'ecdsa-sha2-nistp256',
|
|
121
|
+
'ecdsa-sha2-nistp384',
|
|
122
|
+
'ecdsa-sha2-nistp521',
|
|
123
|
+
'rsa-sha2-512',
|
|
124
|
+
'rsa-sha2-256',
|
|
125
|
+
'ssh-rsa',
|
|
126
|
+
'ssh-dss',
|
|
127
|
+
],
|
|
128
|
+
hmac: [
|
|
129
|
+
'hmac-sha2-256-etm@openssh.com',
|
|
130
|
+
'hmac-sha2-512-etm@openssh.com',
|
|
131
|
+
'hmac-sha1-etm@openssh.com',
|
|
132
|
+
'hmac-sha2-256',
|
|
133
|
+
'hmac-sha2-512',
|
|
134
|
+
'hmac-sha1',
|
|
135
|
+
'hmac-md5',
|
|
136
|
+
'hmac-sha2-256-96',
|
|
137
|
+
'hmac-sha2-512-96',
|
|
138
|
+
// 'hmac-ripemd160',
|
|
139
|
+
// 'hmac-sha1-96',
|
|
140
|
+
// 'hmac-md5-96',
|
|
141
|
+
],
|
|
75
142
|
},
|
|
76
143
|
};
|
|
77
144
|
} else {
|
|
145
|
+
// console.log('*******************');
|
|
78
146
|
console.log('SFTP - Using User/Pwd');
|
|
147
|
+
// console.log('SFTP - Username: ' + n.username);
|
|
148
|
+
// console.log('SFTP - Password: ' + n.password);
|
|
149
|
+
// console.log('SFTP - Using privateKey: ' + keyFile + ' Length: ' + keyData?.toString().length);
|
|
150
|
+
// console.log('*******************');
|
|
79
151
|
this.options = {
|
|
80
152
|
host: n.host || 'localhost',
|
|
81
153
|
port: n.port || 21,
|
|
82
154
|
username: n.username,
|
|
83
155
|
password: n.password,
|
|
84
156
|
algorithms: {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
157
|
+
kex: [
|
|
158
|
+
'curve25519-sha256',
|
|
159
|
+
'curve25519-sha256@libssh.org',
|
|
160
|
+
'ecdh-sha2-nistp256',
|
|
161
|
+
'ecdh-sha2-nistp384',
|
|
162
|
+
'ecdh-sha2-nistp521',
|
|
163
|
+
'diffie-hellman-group-exchange-sha256',
|
|
164
|
+
'diffie-hellman-group14-sha256',
|
|
165
|
+
'diffie-hellman-group15-sha512',
|
|
166
|
+
'diffie-hellman-group16-sha512',
|
|
167
|
+
'diffie-hellman-group17-sha512',
|
|
168
|
+
'diffie-hellman-group18-sha512',
|
|
169
|
+
'diffie-hellman-group-exchange-sha1',
|
|
170
|
+
'diffie-hellman-group14-sha1',
|
|
171
|
+
'diffie-hellman-group1-sha1',
|
|
172
|
+
],
|
|
173
|
+
cipher: [
|
|
174
|
+
'chacha20-poly1305@openssh.com',
|
|
175
|
+
'aes128-gcm',
|
|
176
|
+
'aes128-gcm@openssh.com',
|
|
177
|
+
'aes256-gcm',
|
|
178
|
+
'aes256-gcm@openssh.com',
|
|
179
|
+
'aes128-ctr',
|
|
180
|
+
'aes192-ctr',
|
|
181
|
+
'aes256-ctr',
|
|
182
|
+
'3des-cbc',
|
|
183
|
+
'aes256-cbc',
|
|
184
|
+
'aes192-cbc',
|
|
185
|
+
'aes128-cbc',
|
|
186
|
+
// 'arcfour256',
|
|
187
|
+
// 'arcfour128',
|
|
188
|
+
// 'arcfour',
|
|
189
|
+
// 'blowfish-cbc',
|
|
190
|
+
// 'ast128-cbc',
|
|
191
|
+
],
|
|
192
|
+
serverHostKey: [
|
|
193
|
+
'ssh-ed25519',
|
|
194
|
+
'ecdsa-sha2-nistp256',
|
|
195
|
+
'ecdsa-sha2-nistp384',
|
|
196
|
+
'ecdsa-sha2-nistp521',
|
|
197
|
+
'rsa-sha2-512',
|
|
198
|
+
'rsa-sha2-256',
|
|
199
|
+
'ssh-rsa',
|
|
200
|
+
'ssh-dss',
|
|
201
|
+
],
|
|
202
|
+
hmac: [
|
|
203
|
+
'hmac-sha2-256-etm@openssh.com',
|
|
204
|
+
'hmac-sha2-512-etm@openssh.com',
|
|
205
|
+
'hmac-sha1-etm@openssh.com',
|
|
206
|
+
'hmac-sha2-256',
|
|
207
|
+
'hmac-sha2-512',
|
|
208
|
+
'hmac-sha1',
|
|
209
|
+
'hmac-md5',
|
|
210
|
+
'hmac-sha2-256-96',
|
|
211
|
+
'hmac-sha2-512-96',
|
|
212
|
+
// 'hmac-ripemd160',
|
|
213
|
+
// 'hmac-sha1-96',
|
|
214
|
+
// 'hmac-md5-96',
|
|
215
|
+
],
|
|
89
216
|
},
|
|
90
217
|
};
|
|
91
218
|
}
|
|
@@ -104,7 +231,7 @@ module.exports = function (RED) {
|
|
|
104
231
|
|
|
105
232
|
if (this.sftpConfig) {
|
|
106
233
|
const node = this;
|
|
107
|
-
node.on('input', function (msg, send, done) {
|
|
234
|
+
node.on('input', async function (msg, send, done) {
|
|
108
235
|
try {
|
|
109
236
|
node.workdir = node.workdir || msg.workdir || './';
|
|
110
237
|
node.fileExtension = node.fileExtension || msg.fileExtension || '';
|
|
@@ -115,140 +242,111 @@ module.exports = function (RED) {
|
|
|
115
242
|
node.sftpConfig.options.username = msg.user || node.sftpConfig.options.username || '';
|
|
116
243
|
node.sftpConfig.options.password = msg.password || node.sftpConfig.options.password || '';
|
|
117
244
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (err) {
|
|
122
|
-
// node.error(err.toString(), msg);
|
|
123
|
-
node.status({ fill: 'red', shape: 'ring', text: 'failed' });
|
|
124
|
-
done(err);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
node.status({});
|
|
128
|
-
conn.end();
|
|
129
|
-
msg.payload = result;
|
|
130
|
-
node.send(msg);
|
|
131
|
-
};
|
|
245
|
+
// console.log('========');
|
|
246
|
+
// console.log(node.sftpConfig.options.privateKey);
|
|
247
|
+
// console.log('========');
|
|
132
248
|
|
|
133
|
-
conn
|
|
134
|
-
switch (node.operation) {
|
|
135
|
-
case 'list':
|
|
136
|
-
conn.sftp(function (err, sftp) {
|
|
137
|
-
if (err) {
|
|
138
|
-
// node.error(err, msg);
|
|
139
|
-
done(err);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
sftp.readdir(node.workdir, node.sendMsg);
|
|
143
|
-
});
|
|
144
|
-
break;
|
|
145
|
-
case 'get':
|
|
146
|
-
conn.sftp(function (err, sftp) {
|
|
147
|
-
if (err) {
|
|
148
|
-
// node.error(err, msg);
|
|
149
|
-
done(err);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let ftpfilename = node.workdir + node.filename;
|
|
249
|
+
// let conn = new sftp();
|
|
153
250
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
251
|
+
// conn.on('ready', async function () {
|
|
252
|
+
const Client = require('ssh2-sftp-client');
|
|
253
|
+
const client = new Client();
|
|
254
|
+
try {
|
|
255
|
+
node.status({ fill: 'gray', shape: 'ring', text: 'connection...' });
|
|
256
|
+
await client.connect(node.sftpConfig.options);
|
|
257
|
+
node.status({ fill: 'green', shape: 'ring', text: 'connected' });
|
|
258
|
+
} catch (err) {
|
|
259
|
+
node.status({ fill: 'red', shape: 'ring', text: 'connection failed.' });
|
|
260
|
+
done(err);
|
|
261
|
+
console.error(err.message);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
157
264
|
|
|
158
|
-
|
|
159
|
-
|
|
265
|
+
switch (node.operation) {
|
|
266
|
+
case 'list':
|
|
267
|
+
try {
|
|
268
|
+
const result = await client.list(node.workdir);
|
|
269
|
+
node.status({ fill: 'green', shape: 'dot', text: 'list done' });
|
|
270
|
+
await client.end();
|
|
271
|
+
msg.payload = {};
|
|
272
|
+
msg.payload = result;
|
|
273
|
+
node.send(msg);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
node.status({ fill: 'red', shape: 'ring', text: 'list failed' });
|
|
276
|
+
done(err);
|
|
277
|
+
console.error(err.message);
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
160
280
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
281
|
+
case 'get':
|
|
282
|
+
try {
|
|
283
|
+
let ftpfilename = node.workdir + node.filename;
|
|
284
|
+
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
164
285
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
} else if (node.filename == '') {
|
|
193
|
-
let d = new Date();
|
|
194
|
-
let guid = d.getTime().toString();
|
|
195
|
-
if (node.fileExtension == '') node.fileExtension = '.txt';
|
|
196
|
-
newFile = node.workdir + guid + node.fileExtension;
|
|
197
|
-
} else {
|
|
198
|
-
newFile = node.workdir + node.filename;
|
|
199
|
-
}
|
|
286
|
+
const result = await client.get(ftpfilename);
|
|
287
|
+
await client.end();
|
|
288
|
+
node.status({ fill: 'green', shape: 'dot', text: 'get done' });
|
|
289
|
+
// conn.end();
|
|
290
|
+
// console.log('SFTP Read Chunks ' + counter + ' Length: ' + buf.length);
|
|
291
|
+
msg.payload = {};
|
|
292
|
+
msg.payload.filedata = result;
|
|
293
|
+
msg.payload.filename = ftpfilename;
|
|
294
|
+
node.send(msg);
|
|
295
|
+
} catch (err) {
|
|
296
|
+
node.status({ fill: 'red', shape: 'ring', text: 'get failed' });
|
|
297
|
+
done(err);
|
|
298
|
+
console.error(err.message);
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
301
|
+
case 'put':
|
|
302
|
+
let newFile = '';
|
|
303
|
+
if (msg.payload.filename) {
|
|
304
|
+
newFile = msg.payload.filename;
|
|
305
|
+
} else if (node.filename == '') {
|
|
306
|
+
let d = new Date();
|
|
307
|
+
let guid = d.getTime().toString();
|
|
308
|
+
if (node.fileExtension == '') node.fileExtension = '.txt';
|
|
309
|
+
newFile = node.workdir + guid + node.fileExtension;
|
|
310
|
+
} else {
|
|
311
|
+
newFile = node.workdir + node.filename;
|
|
312
|
+
}
|
|
200
313
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
314
|
+
let msgData = '';
|
|
315
|
+
msgData = msg.payload.filedata ? msg.payload.filedata : JSON.stringify(msg.payload);
|
|
316
|
+
// console.log(newFile);
|
|
317
|
+
node.status({});
|
|
318
|
+
try {
|
|
319
|
+
await client.put(msgData, newFile);
|
|
320
|
+
node.status({ fill: 'green', shape: 'dot', text: 'put done' });
|
|
321
|
+
await client.end();
|
|
322
|
+
msg.payload = {};
|
|
323
|
+
msg.payload.filename = newFile;
|
|
324
|
+
node.send(msg);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
node.status({ fill: 'red', shape: 'ring', text: 'put failed' });
|
|
327
|
+
done(err);
|
|
328
|
+
console.error(err.message);
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
204
331
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
let ftpfilename = node.workdir + node.filename;
|
|
226
|
-
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
227
|
-
console.log('SFTP Deleting File: ' + ftpfilename);
|
|
228
|
-
sftp.unlink(ftpfilename, function (err) {
|
|
229
|
-
if (err) {
|
|
230
|
-
// node.error(err, msg);
|
|
231
|
-
done(err);
|
|
232
|
-
return;
|
|
233
|
-
} else {
|
|
234
|
-
console.log('SFTP file unlinked');
|
|
235
|
-
node.status({});
|
|
236
|
-
msg.payload = {};
|
|
237
|
-
msg.payload.filename = ftpfilename;
|
|
238
|
-
node.send(msg);
|
|
239
|
-
}
|
|
240
|
-
conn.end();
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
conn.on('error', function (error) {
|
|
247
|
-
// node.error(error, msg);
|
|
248
|
-
done(error);
|
|
249
|
-
return;
|
|
250
|
-
});
|
|
251
|
-
conn.connect(node.sftpConfig.options);
|
|
332
|
+
case 'delete':
|
|
333
|
+
try {
|
|
334
|
+
let ftpfilename = node.workdir + node.filename;
|
|
335
|
+
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
336
|
+
console.log('SFTP Deleting File: ' + ftpfilename);
|
|
337
|
+
await client.delete(ftpfilename);
|
|
338
|
+
node.status({ fill: 'green', shape: 'dot', text: 'delete done' });
|
|
339
|
+
await client.end();
|
|
340
|
+
msg.payload = {};
|
|
341
|
+
msg.payload.filename = ftpfilename;
|
|
342
|
+
node.send(msg);
|
|
343
|
+
} catch (err) {
|
|
344
|
+
node.status({ fill: 'red', shape: 'ring', text: 'delete failed' });
|
|
345
|
+
done(err);
|
|
346
|
+
console.error(err.message);
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
252
350
|
} catch (error) {
|
|
253
351
|
// node.error(error, msg);
|
|
254
352
|
done(error);
|
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.10.1",
|
|
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": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ftp": "^0.3.10",
|
|
37
37
|
"jsftp": "git+https://github.com/sergi/jsftp.git",
|
|
38
|
-
"ssh2-sftp-client": "^
|
|
38
|
+
"ssh2-sftp-client": "^9.0.4",
|
|
39
39
|
"basic-ftp": "^5.0.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|