@yousolution/node-red-contrib-you-ftp-sftp 1.8.9
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/LICENSE +177 -0
- package/README.md +48 -0
- package/data/.gitkeep +0 -0
- package/docker-compose.yml +14 -0
- package/nodes/ftp.html +172 -0
- package/nodes/ftp.js +176 -0
- package/nodes/sftp.html +197 -0
- package/nodes/sftp.js +263 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @yousolution/node-red-contrib-you-ftp-sftp
|
|
2
|
+
|
|
3
|
+
A Node-RED node to FTP and SFTP Client (fork node-red-contrib-ftp-sftp). Please log issues in the repo for assistance.
|
|
4
|
+
(https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Run the following command in the root directory of your Node-RED install
|
|
9
|
+
|
|
10
|
+
npm install node-red-contrib-ftp-sftp
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
process.env.SFTP_SSH_KEY_FILE - If you want to use private SSH key set this environment variable
|
|
15
|
+
|
|
16
|
+
## SFTP & FTP
|
|
17
|
+
|
|
18
|
+
PUT - Set msg.payload.filedata to the file contents you want pushed and will be uploaded to {GUID}.FileExtension. If you need more changes file request to github.
|
|
19
|
+
|
|
20
|
+
GET - Set msg.payload.filename to get the file or will use Workdir + Filename in configuration. Leave configuration blank to set in code.
|
|
21
|
+
|
|
22
|
+
DELETE - Set msg.payload.filename to delete the file or will use Workdir + Filename in configuration. Leave configuration blank to set in code.
|
|
23
|
+
|
|
24
|
+
LIST - Uses the workdir
|
|
25
|
+
|
|
26
|
+
## Sample Function Node
|
|
27
|
+
|
|
28
|
+
<PRE>
|
|
29
|
+
// ----------------------------------------------------
|
|
30
|
+
// All functions above use information.
|
|
31
|
+
// Sample Javascript Used In Function Node
|
|
32
|
+
// ----------------------------------------------------
|
|
33
|
+
msg.payload = {};
|
|
34
|
+
msg.payload.filename="./SAMPLE_FILE.txt"; // Full Path
|
|
35
|
+
msg.payload.filedata='{}'; // Needs to be a string
|
|
36
|
+
return msg;
|
|
37
|
+
// ----------------------------------------------------
|
|
38
|
+
</PRE>
|
|
39
|
+
|
|
40
|
+
## Acknowledgements
|
|
41
|
+
|
|
42
|
+
The node-red-contrib-force uses the following open source software:
|
|
43
|
+
|
|
44
|
+
- [node-ftp-sftp](https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp): node-ftp is an FTP and SFTP client module for node.js that provides an asynchronous interface for communicating with an FTP and SFTP servers.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
See [license](https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp/blob/master/LICENSE) (Apache License Version 2.0).
|
package/data/.gitkeep
ADDED
|
File without changes
|
package/nodes/ftp.html
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright 2014 Atsushi Kojo.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
-->
|
|
16
|
+
|
|
17
|
+
<script type="text/x-red" data-template-name="ftp">
|
|
18
|
+
<div class="form-row">
|
|
19
|
+
<label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
|
|
20
|
+
<input type="text" id="node-config-input-host" placeholder="localhost" style="width: 40%;" />
|
|
21
|
+
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
|
22
|
+
<input type="text" id="node-config-input-port" placeholder="21" style="width:45px">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
|
|
26
|
+
<input type="text" id="node-config-input-user" placeholder="anonymous" />
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
|
|
30
|
+
<input type="password" id="node-config-input-password">
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-config-input-connTimeout"><i class="fa fa-clock-o"></i> Connection Timeout</label>
|
|
34
|
+
<input type="text" id="node-config-input-connTimeout" placeholder="10000">
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-config-input-pasvTimeout"><i class="fa fa-clock-o"></i> PASV Timeout</label>
|
|
38
|
+
<input type="text" id="node-config-input-pasvTimeout" placeholder="10000">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-config-input-keepalive"><i class="fa fa-clock-o"></i> Keepalive</label>
|
|
42
|
+
<input type="text" id="node-config-input-keepalive" placeholder="10000">
|
|
43
|
+
</div>
|
|
44
|
+
<div class="form-row">
|
|
45
|
+
<label for="node-input-secure"><i class="fa fa-key"></i> Data connection encryption</label>
|
|
46
|
+
<input type="checkbox" id="node-input-secure" placeholder="once" style="width: 10%; vertical-align: top;">
|
|
47
|
+
<label for="node-config-input-secureOptions" style="width: 20%; vertical-align: top;"> Secure Options</label>
|
|
48
|
+
<input type="text" id="node-config-input-secureOptions" style="width: 35%; vertical-align: top;">
|
|
49
|
+
</div>
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
RED.nodes.registerType('ftp', {
|
|
54
|
+
category: 'config',
|
|
55
|
+
color:"BurlyWood",
|
|
56
|
+
defaults: {
|
|
57
|
+
host: { value: '' },
|
|
58
|
+
port: { value: '' },
|
|
59
|
+
secure: { value: false },
|
|
60
|
+
secureOptions: { value: '' },
|
|
61
|
+
user: { value: '' },
|
|
62
|
+
connTimeout: { value: '' },
|
|
63
|
+
pasvTimeout: { value: '' },
|
|
64
|
+
keepalive: { value: '' },
|
|
65
|
+
password: { value: '', required: true }
|
|
66
|
+
},
|
|
67
|
+
label: function() {
|
|
68
|
+
return this.host
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<script type="text/x-red" data-template-name="ftp in">
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-ftp"><i class="fa fa-user"></i> Add new FTP Server</label>
|
|
76
|
+
<input type="text" id="node-input-ftp">
|
|
77
|
+
</div>
|
|
78
|
+
<div class="form-row">
|
|
79
|
+
<label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
|
|
80
|
+
<select type="text" id="node-input-operation">
|
|
81
|
+
<option value="list">list</option>
|
|
82
|
+
<option value="get">get</option>
|
|
83
|
+
<option value="put">put</option>
|
|
84
|
+
<option value="delete">delete</option>
|
|
85
|
+
</select>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="form-row">
|
|
88
|
+
<label for="node-input-workdir"><i class="fa fa-folder-open"></i> Working Directory</label>
|
|
89
|
+
<input type="text" id="node-input-workdir" placeholder="Working Directory">
|
|
90
|
+
</div>
|
|
91
|
+
<div class="form-row input-filename-row hidden">
|
|
92
|
+
<label for="node-input-filename"><i class="fa fa-file"></i> Filename</label>
|
|
93
|
+
<input type="text" id="node-input-filename" placeholder="Filename">
|
|
94
|
+
</div>
|
|
95
|
+
<div class="form-row input-fileExtension-row hidden">
|
|
96
|
+
<label for="node-input-fileExtension"><i class="fa fa-file"></i> File Extension</label>
|
|
97
|
+
<input type="text" id="node-input-fileExtension" placeholder="File Extension">
|
|
98
|
+
</div>
|
|
99
|
+
<div class="form-row input-savedir-row hidden">
|
|
100
|
+
<label for="node-input-savedir"><i class="fa fa-folder-open"></i> Save Directory</label>
|
|
101
|
+
<input type="text" id="node-input-savedir" placeholder="Save Directory">
|
|
102
|
+
</div>
|
|
103
|
+
<div class="form-row input-localFilename-row hidden">
|
|
104
|
+
<label for="node-input-localFilename"><i class="fa fa-file"></i> Local Filename</label>
|
|
105
|
+
<input type="text" id="node-input-localFilename" placeholder="Local Filename">
|
|
106
|
+
</div>
|
|
107
|
+
<div class="form-row">
|
|
108
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
109
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
110
|
+
</div>
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<script type="text/x-red" data-help-name="ftp in">
|
|
114
|
+
<h1>FTP Client</h1>
|
|
115
|
+
<p>
|
|
116
|
+
<b>Node config:</b>
|
|
117
|
+
<ul>
|
|
118
|
+
<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>
|
|
119
|
+
<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>
|
|
120
|
+
<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>
|
|
121
|
+
<li><b>LIST</b> - Uses the workdir</li>
|
|
122
|
+
</ul>
|
|
123
|
+
</p>
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<script type="text/javascript">
|
|
127
|
+
RED.nodes.registerType('ftp in', {
|
|
128
|
+
category: 'storage-input',
|
|
129
|
+
color:"BurlyWood",
|
|
130
|
+
defaults: {
|
|
131
|
+
ftp: { type: 'ftp', required: true },
|
|
132
|
+
operation: { value: 'list', required: true },
|
|
133
|
+
filename: { value: '' },
|
|
134
|
+
localFilename: { value: '' },
|
|
135
|
+
fileExtension: { value: '.txt' },
|
|
136
|
+
workdir: { value: '' },
|
|
137
|
+
savedir: { value: '' },
|
|
138
|
+
name: { value: '' }
|
|
139
|
+
},
|
|
140
|
+
inputs: 1,
|
|
141
|
+
outputs: 1,
|
|
142
|
+
icon: "file.png",
|
|
143
|
+
label: function () {
|
|
144
|
+
var ftpNode = RED.nodes.node(this.ftp);
|
|
145
|
+
return this.name || 'ftp';
|
|
146
|
+
},
|
|
147
|
+
labelStyle: function () {
|
|
148
|
+
return this.name ? 'node_label_italic' : '';
|
|
149
|
+
},
|
|
150
|
+
oneditprepare: function () {
|
|
151
|
+
var filename = $(".input-filename-row");
|
|
152
|
+
var fileExtension = $(".input-fileExtension-row");
|
|
153
|
+
$("#node-input-operation").change(function () {
|
|
154
|
+
var id = $("#node-input-operation option:selected").val();
|
|
155
|
+
console.log(id);
|
|
156
|
+
if (id == 'list') {
|
|
157
|
+
filename.hide();
|
|
158
|
+
fileExtension.hide();
|
|
159
|
+
} else if (id == 'put') {
|
|
160
|
+
filename.show();
|
|
161
|
+
fileExtension.show();
|
|
162
|
+
} else if (id =='get') {
|
|
163
|
+
filename.show();
|
|
164
|
+
fileExtension.hide();
|
|
165
|
+
} else {
|
|
166
|
+
filename.show();
|
|
167
|
+
fileExtension.hide();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
</script>
|
package/nodes/ftp.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2015 Atsushi Kojo.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
module.exports = function (RED) {
|
|
18
|
+
'use strict';
|
|
19
|
+
var ftp = require('ftp');
|
|
20
|
+
var fs = require('fs');
|
|
21
|
+
|
|
22
|
+
const ReadableStream = require('stream');
|
|
23
|
+
|
|
24
|
+
function FtpNode(n) {
|
|
25
|
+
RED.nodes.createNode(this, n);
|
|
26
|
+
var node = this;
|
|
27
|
+
|
|
28
|
+
this.options = {
|
|
29
|
+
host: n.host || 'localhost',
|
|
30
|
+
port: n.port || 21,
|
|
31
|
+
secure: n.secure || false,
|
|
32
|
+
secureOptions: n.secureOptions,
|
|
33
|
+
user: n.user || 'anonymous',
|
|
34
|
+
password: n.password || 'anonymous@',
|
|
35
|
+
pass: n.password || 'anonymous@',
|
|
36
|
+
connTimeout: n.connTimeout || 10000,
|
|
37
|
+
pasvTimeout: n.pasvTimeout || 10000,
|
|
38
|
+
keepalive: n.keepalive || 10000,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
RED.nodes.registerType('ftp', FtpNode);
|
|
43
|
+
|
|
44
|
+
function FtpInNode(n) {
|
|
45
|
+
RED.nodes.createNode(this, n);
|
|
46
|
+
this.ftp = n.ftp;
|
|
47
|
+
this.operation = n.operation;
|
|
48
|
+
this.filename = n.filename;
|
|
49
|
+
this.fileExtension = n.fileExtension;
|
|
50
|
+
this.workdir = n.workdir;
|
|
51
|
+
this.ftpConfig = RED.nodes.getNode(this.ftp);
|
|
52
|
+
|
|
53
|
+
if (this.ftpConfig) {
|
|
54
|
+
var node = this;
|
|
55
|
+
// console.log("FTP ftpConfig: " + JSON.stringify(this.ftpConfig));
|
|
56
|
+
node.on('input', (msg, send, done) => {
|
|
57
|
+
try {
|
|
58
|
+
node.workdir = node.workdir || msg.workdir || './';
|
|
59
|
+
node.fileExtension = node.fileExtension || msg.fileExtension || '';
|
|
60
|
+
|
|
61
|
+
/*FTP options*/
|
|
62
|
+
node.ftpConfig.options.host = msg.host || node.ftpConfig.options.host;
|
|
63
|
+
node.ftpConfig.options.port = msg.port || node.ftpConfig.options.port;
|
|
64
|
+
node.ftpConfig.options.user = msg.user || node.ftpConfig.options.user;
|
|
65
|
+
node.ftpConfig.options.password = msg.password || node.ftpConfig.options.password;
|
|
66
|
+
node.ftpConfig.options.pass = msg.pass || msg.password || node.ftpConfig.options.pass;
|
|
67
|
+
|
|
68
|
+
var JSFtp = require('jsftp');
|
|
69
|
+
|
|
70
|
+
switch (node.operation) {
|
|
71
|
+
case 'list':
|
|
72
|
+
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
73
|
+
console.log('FTP List:' + node.workdir.toString());
|
|
74
|
+
Ftp.ls(node.workdir, (err, data) => {
|
|
75
|
+
// console.log(data);
|
|
76
|
+
msg.payload = data;
|
|
77
|
+
node.send(msg);
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
case 'get':
|
|
81
|
+
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
82
|
+
var ftpfilename = node.workdir + node.filename;
|
|
83
|
+
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
84
|
+
var str = '';
|
|
85
|
+
console.log('FTP Get:' + ftpfilename);
|
|
86
|
+
Ftp.get(ftpfilename, (err, socket) => {
|
|
87
|
+
if (err) {
|
|
88
|
+
// node.error(err, msg);
|
|
89
|
+
done(err);
|
|
90
|
+
} else {
|
|
91
|
+
socket.on('data', (d) => {
|
|
92
|
+
str += d.toString();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
socket.on('close', (err) => {
|
|
96
|
+
if (err) {
|
|
97
|
+
// node.error(err, msg);
|
|
98
|
+
done(err);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
node.status({});
|
|
102
|
+
msg.payload = {};
|
|
103
|
+
msg.payload.filedata = str;
|
|
104
|
+
msg.payload.filename = ftpfilename;
|
|
105
|
+
node.send(msg);
|
|
106
|
+
});
|
|
107
|
+
socket.resume();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
break;
|
|
111
|
+
case 'put':
|
|
112
|
+
var newFile = '';
|
|
113
|
+
if (msg.payload.filename) {
|
|
114
|
+
newFile = msg.payload.filename;
|
|
115
|
+
} else if (node.filename == '') {
|
|
116
|
+
var d = new Date();
|
|
117
|
+
var guid = d.getTime().toString();
|
|
118
|
+
if (node.fileExtension == '') node.fileExtension = '.txt';
|
|
119
|
+
newFile = node.workdir + guid + node.fileExtension;
|
|
120
|
+
} else {
|
|
121
|
+
newFile = node.workdir + node.filename;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var msgData = '';
|
|
125
|
+
if (msg.payload.filedata) msgData = msg.payload.filedata;
|
|
126
|
+
else msgData = JSON.stringify(msg.payload);
|
|
127
|
+
|
|
128
|
+
console.log('FTP Put:' + newFile);
|
|
129
|
+
|
|
130
|
+
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
131
|
+
|
|
132
|
+
var buffer = new Buffer(msgData);
|
|
133
|
+
|
|
134
|
+
Ftp.put(buffer, newFile, (err) => {
|
|
135
|
+
if (err) {
|
|
136
|
+
// node.error(err, msg);
|
|
137
|
+
done(err);
|
|
138
|
+
} else {
|
|
139
|
+
node.status({});
|
|
140
|
+
msg.payload = {};
|
|
141
|
+
msg.payload.filename = newFile;
|
|
142
|
+
node.send(msg);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case 'delete':
|
|
147
|
+
var delFile = '';
|
|
148
|
+
if (msg.payload.filename) delFile = msg.payload.filename;
|
|
149
|
+
else delFile = node.workdir + node.filename;
|
|
150
|
+
console.log('FTP Delete:' + delFile);
|
|
151
|
+
var Ftp = new JSFtp(node.ftpConfig.options);
|
|
152
|
+
Ftp.raw('dele', delFile, (err, data) => {
|
|
153
|
+
if (err) {
|
|
154
|
+
// node.error(err, msg);
|
|
155
|
+
done(err);
|
|
156
|
+
} else {
|
|
157
|
+
node.status({});
|
|
158
|
+
msg.payload = {};
|
|
159
|
+
msg.payload.filename = delFile;
|
|
160
|
+
node.send(msg);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.log('FTP Caught Error:' + error);
|
|
167
|
+
// node.error(error, msg);
|
|
168
|
+
done(error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
172
|
+
this.error('missing ftp configuration');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
RED.nodes.registerType('ftp in', FtpInNode);
|
|
176
|
+
};
|
package/nodes/sftp.html
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright 2014 Atsushi Kojo.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
-->
|
|
16
|
+
|
|
17
|
+
<script type="text/x-red" data-template-name="sftp">
|
|
18
|
+
<div class="form-row">
|
|
19
|
+
<label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
|
|
20
|
+
<input type="text" id="node-config-input-host" placeholder="localhost" style="width: 40%;" />
|
|
21
|
+
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
|
22
|
+
<input type="text" id="node-config-input-port" placeholder="21" style="width:45px">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-username"><i class="fa fa-user"></i> User</label>
|
|
26
|
+
<input type="text" id="node-config-input-username" placeholder="anonymous" />
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
|
|
30
|
+
<input type="password" id="node-config-input-password">
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-config-input-hmac"><i class="fa fa-wrench"></i>hmac</label>
|
|
34
|
+
<select multiple type="text" id="node-config-input-hmac" size="9">
|
|
35
|
+
<option value="hmac-sha2-256">hmac-sha2-256</option>
|
|
36
|
+
<option value="hmac-sha2-512">hmac-sha2-512</option>
|
|
37
|
+
<option value="hmac-sha1">hmac-sha1</option>
|
|
38
|
+
<option value="hmac-md5">hmac-md5</option>
|
|
39
|
+
<option value="hmac-sha2-256-96">hmac-sha2-256-96</option>
|
|
40
|
+
<option value="hmac-sha2-512-96">hmac-sha2-512-96</option>
|
|
41
|
+
<option value="hmac-ripemd160">hmac-ripemd160</option>
|
|
42
|
+
<option value="hmac-sha1-96">hmac-sha1-96</option>
|
|
43
|
+
<option value="hmac-md5-96">hmac-md5-96</option>
|
|
44
|
+
</select>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="form-row">
|
|
47
|
+
<label for="node-config-input-cipher"><i class="fa fa-wrench"></i>cipher</label>
|
|
48
|
+
<select multiple type="text" id="node-config-input-cipher" size="17">
|
|
49
|
+
<option value="aes128-ctr">aes128-ctr</option>
|
|
50
|
+
<option value="aes192-ctr">aes192-ctr</option>
|
|
51
|
+
<option value="aes256-ctr">aes256-ctr</option>
|
|
52
|
+
<option value="aes128-gcm">aes128-gcm (node v0.11.12 or newer)</option>
|
|
53
|
+
<option value="aes128-gcm@openssh.com">aes128-gcm@openssh.com (node v0.11.12 or newer)</option>
|
|
54
|
+
<option value="aes256-gcm">aes256-gcm (node v0.11.12 or newer)</option>
|
|
55
|
+
<option value="aes256-gcm@openssh.com">aes256-gcm@openssh.com (node v0.11.12 or newer)</option>
|
|
56
|
+
<option value="aes256-cbc">aes256-cbc</option>
|
|
57
|
+
<option value="aes192-cbc">aes192-cbc</option>
|
|
58
|
+
<option value="aes128-cbc">aes128-cbc</option>
|
|
59
|
+
<option value="blowfish-cbc">blowfish-cbc</option>
|
|
60
|
+
<option value="3des-cbc">3des-cbc</option>
|
|
61
|
+
<option value="arcfour256">arcfour256</option>
|
|
62
|
+
<option value="arcfour128">arcfour128</option>
|
|
63
|
+
<option value="cast128-cbc">cast128-cbc</option>
|
|
64
|
+
<option value="arcfour">arcfour</option>
|
|
65
|
+
</select>
|
|
66
|
+
</div>
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/javascript">
|
|
70
|
+
RED.nodes.registerType('sftp', {
|
|
71
|
+
category: 'config',
|
|
72
|
+
color:"BurlyWood",
|
|
73
|
+
defaults: {
|
|
74
|
+
host: { value: 'localhost' },
|
|
75
|
+
port: { value: '22' },
|
|
76
|
+
username: { value: '', required: true },
|
|
77
|
+
password: { value: '', required: true },
|
|
78
|
+
hmac: { value: 'hmac-sha2-256,hmac-sha2-512,hmac-sha1', required: true },
|
|
79
|
+
cipher: { value: 'aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm', required: true }
|
|
80
|
+
},
|
|
81
|
+
label: function() {
|
|
82
|
+
return this.host
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<script type="text/x-red" data-template-name="sftp in">
|
|
88
|
+
<div class="form-row">
|
|
89
|
+
<label for="node-input-sftp"><i class="fa fa-user"></i> Add new FTP Server</label>
|
|
90
|
+
<input type="text" id="node-input-sftp">
|
|
91
|
+
</div>
|
|
92
|
+
<div class="form-row">
|
|
93
|
+
<label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
|
|
94
|
+
<select type="text" id="node-input-operation">
|
|
95
|
+
<option value="list">list</option>
|
|
96
|
+
<option value="get">get</option>
|
|
97
|
+
<option value="put">put</option>
|
|
98
|
+
<option value="delete">delete</option>
|
|
99
|
+
</select>
|
|
100
|
+
</div>
|
|
101
|
+
<div class="form-row">
|
|
102
|
+
<label for="node-input-workdir"><i class="fa fa-folder-open"></i> Working Directory</label>
|
|
103
|
+
<input type="text" id="node-input-workdir" placeholder="Working Directory">
|
|
104
|
+
</div>
|
|
105
|
+
<div class="form-row input-filename-row hidden">
|
|
106
|
+
<label for="node-input-filename"><i class="fa fa-file"></i> Filename</label>
|
|
107
|
+
<input type="text" id="node-input-filename" placeholder="Filename">
|
|
108
|
+
</div>
|
|
109
|
+
<div class="form-row input-savedir-row hidden">
|
|
110
|
+
<label for="node-input-savedir"><i class="fa fa-folder-open"></i> Save Directory</label>
|
|
111
|
+
<input type="text" id="node-input-savedir" placeholder="Save Directory">
|
|
112
|
+
</div>
|
|
113
|
+
<div class="form-row input-localFilename-row hidden">
|
|
114
|
+
<label for="node-input-localFilename"><i class="fa fa-file"></i> Local Filename</label>
|
|
115
|
+
<input type="text" id="node-input-localFilename" placeholder="Local Filename">
|
|
116
|
+
</div>
|
|
117
|
+
<div class="form-row input-fileContents-row hidden">
|
|
118
|
+
<label for="node-input-fileContents"><i class="fa fa-file"></i> File Contents</label>
|
|
119
|
+
<input type="text" id="node-input-fileContents" placeholder="File Contents">
|
|
120
|
+
</div>
|
|
121
|
+
<div class="form-row input-fileExtension-row hidden">
|
|
122
|
+
<label for="node-input-fileExtension"><i class="fa fa-file"></i> File Extension</label>
|
|
123
|
+
<input type="text" id="node-input-fileExtension" placeholder="File Extension">
|
|
124
|
+
</div>
|
|
125
|
+
<div class="form-row">
|
|
126
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
127
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
128
|
+
</div>
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<script type="text/x-red" data-help-name="sftp in">
|
|
132
|
+
<h1>SFTP Client</h1>
|
|
133
|
+
<p>
|
|
134
|
+
<b>Node config:</b>
|
|
135
|
+
process.env.<b>SFTP_SSH_KEY_FILE</b> - If you want to use private SSH key set this environment variable
|
|
136
|
+
<ul>
|
|
137
|
+
<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>
|
|
138
|
+
<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>
|
|
139
|
+
<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>
|
|
140
|
+
<li><b>LIST</b> - Uses the workdir</li>
|
|
141
|
+
</ul>
|
|
142
|
+
</p>
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<script type="text/javascript">
|
|
146
|
+
RED.nodes.registerType('sftp in', {
|
|
147
|
+
category: 'storage-input',
|
|
148
|
+
color:"BurlyWood",
|
|
149
|
+
defaults: {
|
|
150
|
+
sftp: { type: 'sftp', required: true },
|
|
151
|
+
operation: { value: 'list', required: true },
|
|
152
|
+
filename: { value: '' },
|
|
153
|
+
localFilename: { value: '' },
|
|
154
|
+
fileContents: { value: '' },
|
|
155
|
+
fileExtension: { value: '.txt' },
|
|
156
|
+
workdir: { value: '' },
|
|
157
|
+
savedir: { value: '' },
|
|
158
|
+
name: { value: '' }
|
|
159
|
+
},
|
|
160
|
+
inputs: 1,
|
|
161
|
+
outputs: 1,
|
|
162
|
+
icon: "file.png",
|
|
163
|
+
label: function () {
|
|
164
|
+
var sftpNode = RED.nodes.node(this.sftp);
|
|
165
|
+
return this.name || 'sftp';
|
|
166
|
+
},
|
|
167
|
+
labelStyle: function () {
|
|
168
|
+
return this.name ? 'node_label_italic' : '';
|
|
169
|
+
},
|
|
170
|
+
oneditprepare: function () {
|
|
171
|
+
var filename = $(".input-filename-row");
|
|
172
|
+
var fileContents = $(".input-fileContents-row");
|
|
173
|
+
var fileExtension = $(".input-fileExtension-row");
|
|
174
|
+
$("#node-input-operation").change(function () {
|
|
175
|
+
var id = $("#node-input-operation option:selected").val();
|
|
176
|
+
console.log(id);
|
|
177
|
+
if (id == 'list') {
|
|
178
|
+
filename.hide();
|
|
179
|
+
fileExtension.hide();
|
|
180
|
+
} else if (id == 'put') {
|
|
181
|
+
filename.show();
|
|
182
|
+
fileContents.hide();
|
|
183
|
+
fileExtension.show();
|
|
184
|
+
} else if (id =='get') {
|
|
185
|
+
filename.show();
|
|
186
|
+
fileExtension.hide();
|
|
187
|
+
} else if (id =='delete') {
|
|
188
|
+
filename.show();
|
|
189
|
+
fileExtension.hide();
|
|
190
|
+
} else {
|
|
191
|
+
filename.show();
|
|
192
|
+
fileExtension.hide();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
</script>
|
package/nodes/sftp.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2017 Joe Gaska
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
// --------------------------------------------------------------------------------------------------------------
|
|
18
|
+
/*
|
|
19
|
+
|
|
20
|
+
TODO
|
|
21
|
+
Add Get
|
|
22
|
+
Add Delete
|
|
23
|
+
|
|
24
|
+
http://ourcodeworld.com/articles/read/133/how-to-create-a-sftp-client-with-node-js-ssh2-in-electron-framework
|
|
25
|
+
|
|
26
|
+
*/
|
|
27
|
+
// --------------------------------------------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
// STILL VALIDATING CONNECTIVITY
|
|
30
|
+
// -- DID validate it works with list/dir
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
|
|
33
|
+
module.exports = function (RED) {
|
|
34
|
+
'use strict';
|
|
35
|
+
|
|
36
|
+
var sftp = require('ssh2').Client;
|
|
37
|
+
var fs = require('fs');
|
|
38
|
+
|
|
39
|
+
function SFtpNode(n) {
|
|
40
|
+
RED.nodes.createNode(this, n);
|
|
41
|
+
var node = this;
|
|
42
|
+
|
|
43
|
+
console.log('SFTP - Config - hmac: ' + n.hmac);
|
|
44
|
+
console.log('SFTP - Config - cipher: ' + n.cipher);
|
|
45
|
+
|
|
46
|
+
var keyFile = null;
|
|
47
|
+
var keyData = null;
|
|
48
|
+
if (process.env.SFTP_SSH_KEY_FILE) {
|
|
49
|
+
keyFile = process.env.SFTP_SSH_KEY_FILE;
|
|
50
|
+
keyFile = require('path').resolve(__dirname, '../../' + keyFile);
|
|
51
|
+
console.log('SFTP_SSH_KEY_FILE: ' + keyFile);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
keyData = fs.readFileSync(keyFile).toString();
|
|
55
|
+
// console.log("[http://wwww.HardingPoint.com PRIVATE KEY] " + keyData);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
keyData = null;
|
|
58
|
+
console.log('SFTP - Read Key File [' + keyFile + '] Exception : ' + e);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (keyFile && keyData) {
|
|
63
|
+
console.log('SFTP - Using privateKey: ' + keyFile + ' Length: ' + keyData.toString().length);
|
|
64
|
+
this.options = {
|
|
65
|
+
host: n.host || 'localhost',
|
|
66
|
+
port: n.port || 21,
|
|
67
|
+
username: n.username,
|
|
68
|
+
password: n.password,
|
|
69
|
+
privateKey: keyData,
|
|
70
|
+
algorithms: {
|
|
71
|
+
// hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96'],
|
|
72
|
+
// cipher: ['aes256-cbc']
|
|
73
|
+
hmac: n.hmac,
|
|
74
|
+
cipher: n.cipher,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
console.log('SFTP - Using User/Pwd');
|
|
79
|
+
this.options = {
|
|
80
|
+
host: n.host || 'localhost',
|
|
81
|
+
port: n.port || 21,
|
|
82
|
+
username: n.username,
|
|
83
|
+
password: n.password,
|
|
84
|
+
algorithms: {
|
|
85
|
+
// hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96'],
|
|
86
|
+
// cipher: ['aes256-cbc']
|
|
87
|
+
hmac: n.hmac,
|
|
88
|
+
cipher: n.cipher,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
RED.nodes.registerType('sftp', SFtpNode);
|
|
95
|
+
|
|
96
|
+
function SFtpInNode(n) {
|
|
97
|
+
RED.nodes.createNode(this, n);
|
|
98
|
+
this.sftp = n.sftp;
|
|
99
|
+
this.operation = n.operation;
|
|
100
|
+
this.filename = n.filename;
|
|
101
|
+
this.fileExtension = n.fileExtension;
|
|
102
|
+
this.workdir = n.workdir;
|
|
103
|
+
this.sftpConfig = RED.nodes.getNode(this.sftp);
|
|
104
|
+
|
|
105
|
+
if (this.sftpConfig) {
|
|
106
|
+
var node = this;
|
|
107
|
+
node.on('input', function (msg, send, done) {
|
|
108
|
+
try {
|
|
109
|
+
node.workdir = node.workdir || msg.workdir || './';
|
|
110
|
+
node.fileExtension = node.fileExtension || msg.fileExtension || '';
|
|
111
|
+
|
|
112
|
+
/*SFTP options*/
|
|
113
|
+
node.sftpConfig.options.host = msg.host || node.sftpConfig.options.host;
|
|
114
|
+
node.sftpConfig.options.port = msg.port || node.sftpConfig.options.port;
|
|
115
|
+
node.sftpConfig.options.username = msg.user || node.sftpConfig.options.username || '';
|
|
116
|
+
node.sftpConfig.options.password = msg.password || node.sftpConfig.options.password || '';
|
|
117
|
+
|
|
118
|
+
var conn = new sftp();
|
|
119
|
+
|
|
120
|
+
this.sendMsg = function (err, result) {
|
|
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
|
+
};
|
|
132
|
+
|
|
133
|
+
conn.on('ready', function () {
|
|
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
|
+
var ftpfilename = node.workdir + node.filename;
|
|
153
|
+
|
|
154
|
+
if (msg.payload.filename) ftpfilename = msg.payload.filename;
|
|
155
|
+
|
|
156
|
+
var bufferarray = [];
|
|
157
|
+
|
|
158
|
+
// Be very careful bufferSize too large causes issues with multi threading
|
|
159
|
+
var stream = sftp.createReadStream(ftpfilename, { highWaterMark: 1024, bufferSize: 1024 });
|
|
160
|
+
|
|
161
|
+
var counter = 0;
|
|
162
|
+
var buf = '';
|
|
163
|
+
var byteSize = 65536;
|
|
164
|
+
|
|
165
|
+
stream
|
|
166
|
+
.on('data', function (d) {
|
|
167
|
+
buf += d;
|
|
168
|
+
counter++;
|
|
169
|
+
// console.log("Read Chunk ("+ counter + "): " + d.length + " Length: " + buf.length);
|
|
170
|
+
})
|
|
171
|
+
.on('end', function () {
|
|
172
|
+
node.status({});
|
|
173
|
+
conn.end();
|
|
174
|
+
console.log('SFTP Read Chunks ' + counter + ' Length: ' + buf.length);
|
|
175
|
+
msg.payload = {};
|
|
176
|
+
msg.payload.filedata = buf;
|
|
177
|
+
msg.payload.filename = ftpfilename;
|
|
178
|
+
node.send(msg);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
case 'put':
|
|
183
|
+
conn.sftp(function (err, sftp) {
|
|
184
|
+
if (err) {
|
|
185
|
+
// node.error(err, msg);
|
|
186
|
+
done(err);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
var newFile = '';
|
|
190
|
+
if (msg.payload.filename) {
|
|
191
|
+
newFile = msg.payload.filename;
|
|
192
|
+
} else if (node.filename == '') {
|
|
193
|
+
var d = new Date();
|
|
194
|
+
var 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
|
+
}
|
|
200
|
+
|
|
201
|
+
var msgData = '';
|
|
202
|
+
if (msg.payload.filedata) msgData = msg.payload.filedata;
|
|
203
|
+
else msgData = JSON.stringify(msg.payload);
|
|
204
|
+
|
|
205
|
+
console.log('SFTP Put:' + newFile);
|
|
206
|
+
var writeStream = sftp.createWriteStream(newFile, { flags: 'w' });
|
|
207
|
+
// var payloadBuff = new Buffer(msgData);
|
|
208
|
+
// writeStream.write(payloadBuff, node.sendMsg);
|
|
209
|
+
writeStream.write(msgData, function (err, result) {
|
|
210
|
+
node.status({});
|
|
211
|
+
conn.end();
|
|
212
|
+
msg.payload = {};
|
|
213
|
+
msg.payload.filename = newFile;
|
|
214
|
+
node.send(msg);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
break;
|
|
218
|
+
case 'delete':
|
|
219
|
+
conn.sftp(function (err, sftp) {
|
|
220
|
+
if (err) {
|
|
221
|
+
// node.error(err, msg);
|
|
222
|
+
done(err);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
var 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);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
// node.error(error, msg);
|
|
254
|
+
done(error);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
this.error('missing sftp configuration');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
RED.nodes.registerType('sftp in', SFtpInNode);
|
|
263
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yousolution/node-red-contrib-you-ftp-sftp",
|
|
3
|
+
"version": "1.8.9",
|
|
4
|
+
"description": "A node-red node that support FTP and SFTP file transfer using $() environment variables to control the ftp connection details",
|
|
5
|
+
"main": "sftp.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"update": "npm pack && mv yousolution-node-red-contrib-you-ftp-sftp-$npm_package_version.tgz ./data && cd data && npm i yousolution-node-red-contrib-you-ftp-sftp-$npm_package_version.tgz && docker-compose restart",
|
|
8
|
+
"test": "mocha 'test/**/*.spec.js'",
|
|
9
|
+
"coverage": "nyc npm run test"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"node-red",
|
|
17
|
+
"ftp",
|
|
18
|
+
"sftp",
|
|
19
|
+
"redconnect"
|
|
20
|
+
],
|
|
21
|
+
"node-red": {
|
|
22
|
+
"nodes": {
|
|
23
|
+
"ftp": "nodes/ftp.js",
|
|
24
|
+
"sftp": "nodes/sftp.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"author": "Andrea Trentin [YouSolution]",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/yousolution-cloud/node-red-contrib-you-ftp-sftp.git#readme",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"ftp": "^0.3.10",
|
|
35
|
+
"jsftp": "git+https://github.com/sergi/jsftp.git",
|
|
36
|
+
"ssh2-sftp-client": "^1.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/chai": "^4.3.0",
|
|
40
|
+
"@types/node-red-node-test-helper": "^0.2.2",
|
|
41
|
+
"@types/sinon": "^10.0.6",
|
|
42
|
+
"chai": "^4.3.4",
|
|
43
|
+
"mocha": "^9.1.3",
|
|
44
|
+
"node-red": "^2.1.4",
|
|
45
|
+
"node-red-node-test-helper": "^0.2.7",
|
|
46
|
+
"nyc": "^15.1.0",
|
|
47
|
+
"sinon": "^12.0.1"
|
|
48
|
+
}
|
|
49
|
+
}
|