-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode-red-sftpco.html
232 lines (210 loc) · 9.54 KB
/
node-red-sftpco.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!-- CREDENTIALS -->
<script type="text/html" data-template-name="SFTP-credentials">
<div class="form-row">
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
<input type="text" id="node-config-input-host">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="fa fa-globe"></i> Port</label>
<input type="text" id="node-config-input-port">
</div>
<div class="form-row">
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-username">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-user"></i> Password</label>
<input type="password" id="node-config-input-password">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('SFTP-credentials',{
category: 'config',
defaults: {
host: { value:"127.0.0.1" },
port: { value:"22" },
username: { value:"" },
password: { value:"" }
},
label: function() {
return this.username+"@"+this.host || "";
}
});
RED.nodes.registerType('SFTP-main',{
category: 'storage',
color: '#E9967A',
paletteLabel: "SFTP",
defaults: {
path: { value:"/" },
method: { value:"" },
remoteFilePath: {
value:"",
validate: () => {
if($("#node-input-remoteFilePath").parent().is(':hidden')) return true
return RED.validators.typedInput("remoteFilePathType")
}
},
remoteFilePathType: { value:"msg" },
localFilePath: {
value:"",
validate: () => {
if($("#node-input-localFilePath").parent().is(':hidden')) return true
return RED.validators.typedInput("localFilePathType")
}
},
localFilePathType: { value:"msg" },
server: { type:"SFTP-credentials", required:true },
outputs: {value:1},
debug: {value:false},
name: {value:""}
},
inputs: 1,
outputs: 1,
outputLabels: [null,'debug output'],
icon: "white-globe.png",
label: function() {
return this.name || this.server.host || "SFTP";
},
oneditprepare: function() {
$("#node-input-remoteFilePath").typedInput({
default:this.remoteFilePathType||'msg',
types:['msg','flow','global','str','jsonata','env'],
typeField: $("#node-input-remoteFilePathType")})
$("#node-input-localFilePath").typedInput({
default:this.localFilePathType||'msg',
types:['msg','flow','global','str','jsonata','env'],
typeField: $("#node-input-localFilePathType")})
$("#node-input-method").change(function() {
$("#node-input-remoteFilePath").parent().hide();
$("#node-input-localFilePath").parent().hide();
$("#node-input-debug").parent().show();
if ($("#node-input-method").val() === "list") {
$("#node-input-remoteFilePath").parent().show();
} else if ($("#node-input-method").val() === "get") {
$("#node-input-remoteFilePath").parent().show();
$("#node-input-localFilePath").parent().show();
} else if ($("#node-input-method").val() === "put") {
$("#node-input-remoteFilePath").parent().show();
$("#node-input-localFilePath").parent().show();
} else if ($("#node-input-method").val() === "delete") {
$("#node-input-remoteFilePath").parent().show();
}
});
},
oneditsave: function() {
this.remoteFilePathType = $("#node-input-remoteFilePathType").val()
this.localFilePathType = $("#node-input-localFilePathType").val()
if ($("#node-input-debug").is(':checked')) {
this.outputs = 2
} else {
this.outputs = 1
}
}
});
</script>
<script type="text/html" data-template-name="SFTP-main">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server">
</div>
<div class="form-row">
<label for="node-input-method"><i class="fa fa-rss"></i> Method</label>
<select id="node-input-method" >
<option value='list'>List</option>
<option value='get'>Get</option>
<option value='put'>Put</option>
<option value='delete'>Delete</option>
</select>
</div>
<div class="form-row">
<label for="node-input-remoteFilePath"><i class="fa fa-dot-circle-o"></i> Remote Path</label>
<input type="text" id="node-input-remoteFilePath" placeholder="Remote File Path">
<input type="hidden" id="node-input-remoteFilePathType">
</div>
<div class="form-row">
<label for="node-input-localFilePath"><i class="fa fa-folder-open"></i> Local Path</label>
<input type="text" id="node-input-localFilePath" placeholder="Local File Path">
<input type="hidden" id="node-input-localFilePathType">
</div>
<div class="form-row">
<label for="node-input-debug"> </label>
<input type="checkbox" id="node-input-debug" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-debug" style="width: auto"><i class="fa fa-bug"></i> Activate second output for debug</label>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="SFTP-main">
<p>An SFTP client for node-red, a wrapper for <a href="https://github.com/jyu213/ssh2-sftp-client">ssh2-sftp-client</a></p>
<dt>server
<span class="property-type">string</span>
</dt>
<dd>the name of the file, with extension</dd>
<dt>method
<span class="property-type">string</span>
</dt>
<dd>the name of the file, with extension</dd>
<dt>remoteFilePath
<span class="property-type">string</span>
</dt>
<dd>the name of the file, with extension</dd>
<dt>localFilePath
<span class="property-type">string</span>
</dt>
<dd>the name of the file, with extension</dd>
<dt>debug
<span class="property-type">string</span>
</dt>
<dd>the name of the file, with extension</dd>
<p>Retrieves a directory listing.</p>
<pre><code>sftp.list(remoteFilePath)
</code></pre>
<p>directory info:</p>
<pre><code>type: // file type(-, d, l)
name: // file name
size: // file size
modifyTime: // file timestamp of modified time
accessTime: // file timestamp of access time
rights: {
user:
group:
other:
},
owner: // user ID
group: // group ID
</code></pre>
<h3><a id="user-content-get" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#get" aria-hidden="true"></a>Get</h3>
<p>get a new readable stream for path. The encoding is passed to Node Stream (<a href="https://nodejs.org/api/stream.html" rel="nofollow">https://nodejs.org/api/stream.html</a>) and it controls how the content is encoded. For example, when downloading binary data, 'null' should be passed (check node stream documentation). Defaults to 'utf8'.</p>
<pre><code>sftp.get(remoteFilePath, [useCompression], [encoding], [addtionalOptions]);
</code></pre>
<h3><a id="user-content-put" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#put" aria-hidden="true"></a>Put</h3>
<p>upload a file. it can be <code>localPath</code> or <code>Buffer</code> or <code>Stream</code>.</p>
<pre><code>sftp.put(localFilePath, remoteFilePath, [useCompression], [encoding], [addtionalOptions]);
sftp.put(Buffer, remoteFilePath, [useCompression], [encoding], [addtionalOptions]);
sftp.put(Stream, remoteFilePath, [useCompression], [encoding], [addtionalOptions]);
</code></pre>
<h3><a id="user-content-mkdir" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#mkdir" aria-hidden="true"></a>Mkdir</h3>
<p>create a new directory.</p>
<pre><code>// recursive default is false, if true, it will create directory recursive
sftp.mkdir(remoteFilePath, recursive);
</code></pre>
<h3><a id="user-content-rmdir" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#rmdir" aria-hidden="true"></a>Rmdir</h3>
<p>remove the directory or file.</p>
<pre><code>// recursive default is false, if true, it will remove directory recursive even if is not empty
sftp.rmdir(localPath, recursive);
</code></pre>
<h3><a id="user-content-delete" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#delete" aria-hidden="true"></a>Delete</h3>
<p>delete file.</p>
<pre><code>sftp.delete(remoteFilePath);
</code></pre>
<h3><a id="user-content-rename" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#rename" aria-hidden="true"></a>Rename</h3>
<p>rename remoteSourcePath to remoteDestPath (removes remoteSourcePath).</p>
<pre><code>sftp.rename(remoteSourcePath, remoteDestPath);
</code></pre>
<h3><a id="user-content-chmod" class="anchor" href="https://github.com/jyu213/ssh2-sftp-client#chmod" aria-hidden="true"></a>Chmod</h3>
<p>modify rights to remoteDestPath file</p>
<pre><code>sftp.chmod(remoteDestPath, mode);
</code></pre>
</script>