Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Hello
I am trying to secure ftp a backup file to a nas
Does anyone have an example?
I use currently the folowing code wich fails with error : * string: 504 TLS/SSL protection required.
Code: -- ftp to NAS
log("System Backup: transfering backup to NAS, host:" .. FTP_TARGET_IP .. ", target:" .. target)
res, err = socket.ftp.put({
host = FTP_TARGET_IP,
user = FTP_TARGET_LOGIN,
password = FTP_TARGET_PW,
type = "i",
argument = target,
source = ltn12.source.file(io.open(dst, "rb")) })
if (err) then
log(err)
log(res)
alert("System Backup: failed, could not ftp to NAS, host:" .. FTP_TARGET_IP .. ", target:" .. target)
end
Thanks
Nicky
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
19.09.2017, 18:56
(This post was last modified: 19.09.2017, 18:56 by Erwin van der Zwart.)
Hi,
Try this:
Code: require('socket.ftp')
-- Get hostname
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()
-- ftp file
ftpfile = string.format('ftp://user:password@192.168.10.1/backup-' .. hostname .. '-' .. os.date('%Y.%m.%d') .. '.tar.gz')
--Create attachment
src = 'backup-' .. os.date('%Y.%m.%d') .. '.tar.gz'
dst = '/home/ftp/' .. src
-- prepare files for backup
os.execute('sh /lib/genohm-scada/web/general/backup.sh')
-- create cleanup archive
os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./')
-- upload to ftp
result, err = socket.ftp.put(ftpfile, io.readfile(dst))
-- error while uploading
if err then
log('FTP upload error: %s', tostring(err))
else
log('file uploaded to external ftp')
end
--Delete created backup file from tmp folder inside HL
os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')
--Delete temp file from HL ftp
os.remove(dst)
BR,
Erwin
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Thank Erwin
But that looks to be a regular FTP, i need sftp?
Thanks
Nicky
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Which LM version do you have?
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
(21.09.2017, 14:24)admin Wrote: Which LM version do you have? Reactor v2 running latest firmware
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Update this package through system config > packages:
https://dl.openrb.com/lm-17/pkg/luasocke...20_mxs.ipk
Then add secure = true to your ftp.put config table. If you get an error that data connection must be encrypted try adding datasecure = true as well. This might not work for all FTP servers and it depends on how the server is configured.
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
22.09.2017, 14:11
Thanks Admin
Close but not yet there
I updated the package and added the option secure = true
on the synology nas: empty file is created
on the logic machine I have an error:"closed"
I added the option secure = true and datasecure = true
on the synology nas: no file is created
on the logic machine I have an error:"503 Use AUTH and PBSZ commands first"
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Ok, can you enable remote diagnostics on your LM and forward port 22, then send me access via PM?
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Thanks for access providing, please install updated package and try again:
https://dl.openrb.com/lm-17/pkg/luasocke...21_mxs.ipk
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
(25.09.2017, 11:29)admin Wrote: Thanks for access providing, please install updated package and try again:
https://dl.openrb.com/lm-17/pkg/luasocke...21_mxs.ipk
Thanks a lot, Works perfectly !
Are you going to include this in future firmwares, or will it be a seperate install?
Nicky
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Yes, it will be included in the future fw releases.
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
Hi!
Is there any update about this?
Can I use sftp in Logic Machine to make a backup in a NAS? Those links are broken
Thanks
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Updated packages are already included in the latest firmware. No need to install anything manually.
SFTP (file transfer over SSH) is not supported yet. This topic is about FTPS which is a secure version of the FTP protocol. Your NAS should support it.
Posts: 94
Threads: 29
Joined: Nov 2020
Reputation:
1
13.03.2024, 09:08
(This post was last modified: 13.03.2024, 09:12 by Kilogica.)
I would like to point out that the script is used in many web servers, both Schneider and LM, and has always worked and still works every day.
when I try to upload the backup to ftp, the upload happens, but the backup has size 0 and if I try to open it it gives me an error. Furthermore, it is logged in the error log
os.remove call blocked. What is going on?
Code: require('socket.ftp')
-- Get hostname
hostname = io.readfile('/proc/sys/kernel/hostname'):trim()
-- ftp file
ftpfile = string.format('ftp://user:pass@ip/backup/' .. os.date('%Y.%m.%w') .. '-' .. hostname .. '.tar.gz;type=i')
--Create attachment
src = 'backup-' .. os.date('%Y.%m.%d') .. '.tar.gz'
dst = '/home/ftp/' .. src
-- prepare files for backup
os.execute('sh /lib/genohm-scada/web/general/backup.sh')
-- create cleanup archive
os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./')
-- upload to ftp
result, err = socket.ftp.put(ftpfile, io.readfile(dst))
-- error while uploading
if err then
log('FTP upload error: %s', tostring(err))
else
log('file uploaded to external ftp')
end
--Delete created backup file from tmp folder inside HL
os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')
--Delete file from HL ftp
os.remove(dst)
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
Which firmware do you use?
------------------------------
Ctrl+F5
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Erwin's code is outdated. This script should be used instead: https://kb.logicmachine.net/scripting/ba...email-ftp/
Posts: 94
Threads: 29
Joined: Nov 2020
Reputation:
1
13.03.2024, 11:27
(This post was last modified: 13.03.2024, 11:30 by Kilogica.)
now it gives me
io.readproc call blocked
os.tmpname call blocked
the problem is on a wiser with firmware 3.0.0
the file si uploaded with dimension zero kylobyte
Code: host = 'ip'
user = 'user'
pass = 'pass'
path = 'backup/webserver-' .. os.date('%Y-%m-%d') .. '.zip'
ftp = require('socket.ftp')
ltn12 = require('ltn12')
webrequest = require('webrequest')
data = webrequest('general', 'backup')
res, err = ftp.put({
host = host,
user = user,
password = pass,
argument = path,
source = ltn12.source.string(data)
})
if not res then
log('FTP error', err)
end
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
Block unsafe functions in scripts: make sure this is disabled
------------------------------
Ctrl+F5
Posts: 94
Threads: 29
Joined: Nov 2020
Reputation:
1
13.03.2024, 11:47
(This post was last modified: 13.03.2024, 11:49 by Kilogica.)
(13.03.2024, 11:29)Daniel Wrote: Block unsafe functions in scripts: make sure this is disabled
Thanks,
the problem partially solved, file loaded but corrupt
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
I just tried it on SL 3.0.0 and it works just fine. Use 7zip for editing.
------------------------------
Ctrl+F5
|