@yousolution/node-red-contrib-you-ftp-sftp
Version:
A node-red node that support FTP and SFTP file transfer using $() environment variables to control the ftp connection details
173 lines (164 loc) • 6.98 kB
HTML
<!--
Copyright 2023 Andrea Trentin.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="ftps">
<div class="form-row">
<label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
<input type="text" id="node-config-input-host" placeholder="localhost" style="width: 40%;" />
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
<input type="text" id="node-config-input-port" placeholder="21" style="width:45px">
</div>
<div class="form-row">
<label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
<input type="text" id="node-config-input-user" placeholder="anonymous" />
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-password">
</div>
<div class="form-row">
<label for="node-config-input-connTimeout"><i class="fa fa-clock-o"></i> Connection Timeout</label>
<input type="text" id="node-config-input-connTimeout" placeholder="10000">
</div>
<div class="form-row">
<label for="node-config-input-pasvTimeout"><i class="fa fa-clock-o"></i> PASV Timeout</label>
<input type="text" id="node-config-input-pasvTimeout" placeholder="10000">
</div>
<div class="form-row">
<label for="node-config-input-keepalive"><i class="fa fa-clock-o"></i> Keepalive</label>
<input type="text" id="node-config-input-keepalive" placeholder="10000">
</div>
<div class="form-row">
<label for="node-input-secure"><i class="fa fa-key"></i> Data connection encryption</label>
<input type="checkbox" id="node-input-secure" placeholder="once" style="width: 10%; vertical-align: top;">
<label for="node-config-input-secureOptions" style="width: 20%; vertical-align: top;"> Secure Options</label>
<input type="text" id="node-config-input-secureOptions" style="width: 35%; vertical-align: top;">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('ftps', {
category: 'config',
color: 'BurlyWood',
defaults: {
host: { value: '' },
port: { value: '' },
secure: { value: false },
secureOptions: { value: '' },
user: { value: '' },
connTimeout: { value: '' },
pasvTimeout: { value: '' },
keepalive: { value: '' },
password: { value: '', required: true },
},
label: function () {
return this.host;
},
});
</script>
<script type="text/x-red" data-template-name="ftps in">
<div class="form-row">
<label for="node-input-ftps"><i class="fa fa-user"></i> Add new FTPs Server</label>
<input type="text" id="node-input-ftps">
</div>
<div class="form-row">
<label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
<select type="text" id="node-input-operation">
<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-workdir"><i class="fa fa-folder-open"></i> Working Directory</label>
<input type="text" id="node-input-workdir" placeholder="Working Directory">
</div>
<div class="form-row input-filename-row hidden">
<label for="node-input-filename"><i class="fa fa-file"></i> Filename</label>
<input type="text" id="node-input-filename" placeholder="Filename">
</div>
<div class="form-row input-fileExtension-row hidden">
<label for="node-input-fileExtension"><i class="fa fa-file"></i> File Extension</label>
<input type="text" id="node-input-fileExtension" placeholder="File Extension">
</div>
<div class="form-row input-savedir-row hidden">
<label for="node-input-savedir"><i class="fa fa-folder-open"></i> Save Directory</label>
<input type="text" id="node-input-savedir" placeholder="Save Directory">
</div>
<div class="form-row input-localFilename-row hidden">
<label for="node-input-localFilename"><i class="fa fa-file"></i> Local Filename</label>
<input type="text" id="node-input-localFilename" placeholder="Local Filename">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="ftp in">
<h1>FTP Client</h1>
<p>
<b>Node config:</b>
<ul>
<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>
<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>
<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>
<li><b>LIST</b> - Uses the workdir</li>
</ul>
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('ftps in', {
category: 'storage-input',
color: 'BurlyWood',
defaults: {
ftps: { type: 'ftps', required: true },
operation: { value: 'list', required: true },
filename: { value: '' },
localFilename: { value: '' },
fileExtension: { value: '.txt' },
workdir: { value: '' },
savedir: { value: '' },
name: { value: '' },
},
inputs: 1,
outputs: 1,
icon: 'file.png',
label: function () {
var ftpsNode = RED.nodes.node(this.ftps);
return this.name || 'ftps';
},
labelStyle: function () {
return this.name ? 'node_label_italic' : '';
},
oneditprepare: function () {
var filename = $('.input-filename-row');
var fileExtension = $('.input-fileExtension-row');
$('#node-input-operation').change(function () {
var id = $('#node-input-operation option:selected').val();
console.log(id);
if (id == 'list') {
filename.hide();
fileExtension.hide();
} else if (id == 'put') {
filename.show();
fileExtension.show();
} else if (id == 'get') {
filename.show();
fileExtension.hide();
} else {
filename.show();
fileExtension.hide();
}
});
},
});
</script>