Logic Machine Forum
Error not sending file via ftp service! - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Error not sending file via ftp service! (/showthread.php?tid=1257)



Error not sending file via ftp service! - phongvucba - 26.02.2018

Hi everybody !
I have this code to save the backup file to the NAS service (using the ftp protocol). On the Lm3 (I use version 20170424), I opened the ftp service (login successful)
On nas synology, i open ftp service (login successful, full privileges for fpt_user directory).
When running the script on LM3 it again error as shown below:
"string: 553 <fpt_user> LM_nha_mau_HN-2018.02.26_12-28.tar.gz: Permission denied."
Have you met this case yet? And where is the error?
Please help me !
Thank so much!


RE: Error not sending file via ftp service! - admin - 26.02.2018

Are you sure it should be fpt_user, but not ftp_user?


RE: Error not sending file via ftp service! - phongvucba - 26.02.2018

yes, I'm sure !
Sad


RE: Error not sending file via ftp service! - admin - 26.02.2018

Have you checked with another FTP client if you can upload files to this account? Also check that you can upload to root folder, or only to a specific folder. You might have to adjust path in FTP upload script on LM.


RE: Error not sending file via ftp service! - phongvucba - 26.02.2018

Thank admin !
I use script:
------------------
---------------
--Take a backup and ftp to NAS
-- name of backup file
src = 'LM_nha_mau_HN-' .. os.date('%Y.%m.%d_%H-%M') .. '.tar.gz'
-- where to put backup file on LM
dst = '/home/ftp/' .. src
-- where to put the backup on NAS
target = '<fpt_user>' .. src

-- prepare files for backup
os.execute('sh /lib/genohm-scada/web/general/backup.sh')

-- create archive
os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./')


-- load the ftp support
local ftp = require("socket.ftp")
local ltn12 = require("ltn12")

-- ftp to NAS
f, e = socket.ftp.put{
host = "100.100.100.99",
user = "fpt_user",
password = "gammajsc",
type = "i",
argument = target,
source = ltn12.source.file(io.open(dst, "rb"))

}
if (e) then
log (e)
log (f)
alert("Could not ftp: ", e, "\n")
end
log("ftp_backup")




-- cleanup
os.execute('cd /home/ftp && rm -rf backup_*')
os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')
-----------------
Am I something wrong? Please help me


RE: Error not sending file via ftp service! - npinguin - 26.02.2018

Hi

Could it be that you configurered sftp?

If so try to use the adapted script below, but you also need a new FTP package which you can find here

please install updated package:
https://dl.openrb.com/lm-17/pkg/luasocket_2.0.2-21_mxs.ipk

Code:
require('socket.ftp')

-------------------------
-- CONFIG
-------------------------
FTP_TARGET_FOLDER =  ''
FTP_TARGET_IP =  ''
FTP_TARGET_LOGIN = ''
FTP_TARGET_PW = ''

-------------------------
-- FUNCTIONS
-------------------------

-- backup the config and transfer it to the nas
function backup()
 
 log("System Backup: started")

 --Take a backup and ftp to NAS
    -- name of backup file
    src = 'backup-' .. os.date('%Y.%m.%d_%H-%M') .. '.tar.gz'
    -- where to put backup file on LM
    dst = '/home/ftp/' .. src

    -- where to put the backup on NAS
    target = FTP_TARGET_FOLDER .. src

    -- prepare files for backup
    os.execute('sh /lib/genohm-scada/web/general/backup.sh')

    -- create archive
    os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./')


    -- 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,
     secure = true,
     datasecure = true,
     type = "i",
     argument = target,
     source = ltn12.source.file(io.open(dst, "rb")) })
 
    if (err) then
   logMsg = "System Backup: failed with error:"
   if (error) then
     logMsg = logMsg .. err
   else
     logMsg = logMsg .. "nil"
   end
   if (res) then
     logMsg = logMsg .. ", result:" .. res
   else
     logMsg = logMsg ..  ", result:nil"
   end
   log(logMsg)
   alert("System Backup: failed, could not ftp to NAS, host:" .. FTP_TARGET_IP .. ", target:" .. target)
   alert(logMsg)
    end
   
    -- cleanup
    os.execute('cd /home/ftp && rm -rf backup_*')
    os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')

 log("System Backup: completed")

end



RE: Error not sending file via ftp service! - phongvucba - 27.02.2018

Thank so much !
I'm will try !


RE: Error not sending file via ftp service! - admin - 27.02.2018

This line is probably incorrect:
Code:
target = '<fpt_user>' .. src

Try this:
Code:
target = 'fpt_user/' .. src

Or this:
Code:
target = src