06.02.2023, 14:15
Hi
I am trying to write files to external ftp. I get the following answer from the ftp-server:
504 Form must be N or T
What does this mean? I have tested the script to a server I set up for testing, and it worked, but in the real server where the files are t o be written I am not able to write.
I am trying to write files to external ftp. I get the following answer from the ftp-server:
504 Form must be N or T
What does this mean? I have tested the script to a server I set up for testing, and it worked, but in the real server where the files are t o be written I am not able to write.
Code:
ftpAdresse = '192.168.0.198'
ftpMappeDaily = '/FTPtest/Daily/'
ftpMappeHistory = '/FTPtest/History/'
username = 'Spacelynk'
pw = 'Test123'
-----------------------------------------------------------------------------------------------------------------------
--Finner alle lamper i anlegget
-----------------------------------------------------------------------------------------------------------------------
lamper = db:getall('SELECT name FROM objects WHERE name LIKE "%TEST_RESULT%"')
-----------------------------------------------------------------------------------------------------------------------
--Navnelister resultater fra test
-----------------------------------------------------------------------------------------------------------------------
LTRF = {
{val = 0, Text = 'Unknown'},
{val = 1, Text = 'Passed in time'},
{val = 2, Text = 'Passed max delay exceeded'},
{val = 3, Text = 'Failed, test executed in time'},
{val = 4, Text = 'Failed, max delay exceeded'},
{val = 5, Text = 'Test manually stopped'},
{val = 6, Text = 'Invalid value; 6'},
{val = 7, Text = 'Invalid value; 7'},
{val = 8, Text = 'Invalid value; 8'},
{val = 9, Text = 'Invalid value; 9'},
{val = 10, Text = 'Invalid value; 10'},
{val = 11, Text = 'Invalid value; 11'},
{val = 12, Text = 'Invalid value; 12'},
{val = 13, Text = 'Invalid value; 13'},
{val = 14, Text = 'Invalid value; 14'},
{val = 15, Text = 'Invalid value; 15'},
}
LTRD = {
{val = 0, Text = 'Unknown'},
{val = 1, Text = 'Passed in time'},
{val = 2, Text = 'Passed max delay exceeded'},
{val = 3, Text = 'Failed, test executed in time'},
{val = 4, Text = 'Failed, max delay exceeded'},
{val = 5, Text = 'Test manually stopped'},
{val = 6, Text = 'Invalid value; 6'},
{val = 7, Text = 'Invalid value; 7'},
{val = 8, Text = 'Invalid value; 8'},
{val = 9, Text = 'Invalid value; 9'},
{val = 10, Text = 'Invalid value; 10'},
{val = 11, Text = 'Invalid value; 11'},
{val = 12, Text = 'Invalid value; 12'},
{val = 13, Text = 'Invalid value; 13'},
{val = 14, Text = 'Invalid value; 14'},
{val = 15, Text = 'Invalid value; 15'},
}
SF = {
{val = 0, Text = 'Unknown'},
{val = 1, Text = 'Started automatically'},
{val = 2, Text = 'Started by Gateway'},
{val = 3, Text = 'Reserved'},
}
SD = {
{val = 0, Text = 'Unknown'},
{val = 1, Text = 'Started automatically'},
{val = 2, Text = 'Started by Gateway'},
{val = 3, Text = 'Reserved'},
}
-----------------------------------------------------------------------------------------------------------------------
--Oppretter filer for lagring av verdier
-----------------------------------------------------------------------------------------------------------------------
now = os.date('*t')
time = {
day = wday,
hour = now.hour,
minute = now.min,
second = now.sec,
}
reportFile = string.format('CurrentReport.csv')
historyFile = string.format('%s-Report.csv', os.date('%d-%m-%Y',log_start))
reportBuffer = {'Resultater fra test.', 'Test startet; ' .. os.date('%d/%m-%Y',log_start) .. ' klokken ' .. time.hour .. '.' .. time.minute ,
'Rom; Lampe; Siste funksjonstest; Siste batteritest; Startmetode FT; Startmetode BT' }
-----------------------------------------------------------------------------------------------------------------------
-- Henter verdier fra lamper
-----------------------------------------------------------------------------------------------------------------------
for _, lampe in ipairs(lamper) do
navn = lampe.name
rom = string.split(navn, ' =')[1]
lampe = '=' .. string.split(string.split(navn, '=')[2], ' ')[1]
--log(rom, lampe)
verdi = grp.getvalue(navn)
--Finner LTRF
for _, linje in ipairs(LTRF) do
if linje.val == verdi.ltrf then
LTRF_text = linje.Text
elseif verdi.ltrf == nil then
LTRF_text = 'Not found'
end
end
--Finner LTRD
for _, linje in ipairs(LTRD) do
if linje.val == verdi.ltrd then
LTRD_text = linje.Text
elseif verdi.ltrd == nil then
LTRD_text = 'Not found'
end
end
--Finner SF
for _, linje in ipairs(SF) do
if linje.val == verdi.sf then
SF_text = linje.Text
elseif verdi.sf == nil then
SF_text = 'Not found'
end
end
--Finner SD
for _, linje in ipairs(SD) do
if linje.val == verdi.sd then
SD_text = linje.Text
elseif verdi.sd == nil then
SD_text = 'Not found'
end
end
table.insert(reportBuffer, rom .. ';' .. lampe .. ';' .. LTRF_text .. ';' .. LTRD_text .. ';' .. SF_text .. ';' .. SD_text)
--log(navn, LTRF_text, LTRD_text, SF_text, SD_text)
--log(navn, verdi)
end
-----------------------------------------------------------------------------------------------------------------------
-- Skriver fil til SL HD
-----------------------------------------------------------------------------------------------------------------------
rapport = string.char(0xEF, 0xBB, 0xBF)
csv = rapport .. table.concat(reportBuffer, '\r\n')
result, err = io.writefile ('/home/ftp/' .. reportFile, csv)
resultHist, err = io.writefile ('/home/ftp/' .. historyFile, csv)
log(result, err)
-----------------------------------------------------------------------------------------------------------------------
-- Skriver fil til FTP; historisk fil og dagens fil
-----------------------------------------------------------------------------------------------------------------------
local ftp = require("socket.ftp")
local ltn12 = require("ltn12")
targetHist = ftpMappeHistory .. historyFile
targetDay = ftpMappeDaily .. reportFile
log(targetHist)
dst = '/home/ftp/' .. historyFile
f, e = socket.ftp.put{
host = ftpAdresse,
user = username,
password = pw,
type = "a n",
argument = targetHist,
source = ltn12.source.file(io.open(dst, "rb"))
}
if (e) then
log (e)
log (f)
alert("Could not ftp: ", e, "\n")
end
log(targetDay)
dst = '/home/ftp/' .. reportFile
f, e = socket.ftp.put{
host = ftpAdresse,
user = username,
password = pw,
type = "a n",
argument = targetDay,
source = ltn12.source.file(io.open(dst, "rb"))
}
if (e) then
log (e)
log (f)
alert("Could not ftp: ", e, "\n")
end
There are 10 kinds of people in the world; those who can read binary and those who don't