This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Cannot Write to Files from LUA Resident Script
#1
Hello,
I'm experiencing file write permission issues and need help resolving them.
 
THE PROBLEM
I have JSON files that my JavaScript code can READ successfully via HTTP, but my LUA resident script CANNOT WRITE to these same files.
 
Files are located at: /user/data/event_definitions.json and /user/data/event_schedules.json
JavaScript reads them successfully via HTTP:
- fetch('/apps/data/event_definitions.json') → Works perfectly
- Files exist and are readable
LUA resident script attempts to write to: /user/data/event_definitions.json
- Result: Permission denied / Cannot open file for writing
 
WHAT WE'VE TRIED
1. Direct write using io.open(filepath, 'w'):
   Result: Returns nil (cannot open file)
2. Added os.execute('chmod 777 /user/data'):
   Result: No effect, still cannot write
3. Write to /tmp/ then copy using os.execute('cp /tmp/file.json /user/data/file.json'):
   Result: Copy command returns exit code 256 (failure)
4. Write to /tmp/ then cat using os.execute('cat /tmp/file.json > /user/data/file.json'):
   Result: Exit code 256 (failure), verification shows file not updated
 
FTP ACCESS
- When logged in via FTP as user "apps": Can see /user/data/ directory with the JSON files
- When logged in via FTP as user "ftp": Root folder is empty
 
QUESTION
 
What is the correct way to make /user/data/ writable by LUA resident scripts?
 
OR
 
What is the recommended directory for storing user data files that:
1. Can be written to by LUA scripts
2. Can be read via HTTP by JavaScript (fetch API)
3. Persists across reboots (not /tmp/)
4. Is accessible via FTP for backup purposes
 
Any guidance would be greatly appreciated!
Reply
#2
(11.12.2025, 16:08)Intelect Wrote: Hello,
I'm experiencing file write permission issues and need help resolving them.
 
THE PROBLEM
I have JSON files that my JavaScript code can READ successfully via HTTP, but my LUA resident script CANNOT WRITE to these same files.
 
Files are located at: /user/data/event_definitions.json and /user/data/event_schedules.json
JavaScript reads them successfully via HTTP:
- fetch('/apps/data/event_definitions.json') → Works perfectly
- Files exist and are readable
LUA resident script attempts to write to: /user/data/event_definitions.json
- Result: Permission denied / Cannot open file for writing
 
WHAT WE'VE TRIED
1. Direct write using io.open(filepath, 'w'):
   Result: Returns nil (cannot open file)
2. Added os.execute('chmod 777 /user/data'):
   Result: No effect, still cannot write
3. Write to /tmp/ then copy using os.execute('cp /tmp/file.json /user/data/file.json'):
   Result: Copy command returns exit code 256 (failure)
4. Write to /tmp/ then cat using os.execute('cat /tmp/file.json > /user/data/file.json'):
   Result: Exit code 256 (failure), verification shows file not updated
 
FTP ACCESS
- When logged in via FTP as user "apps": Can see /user/data/ directory with the JSON files
- When logged in via FTP as user "ftp": Root folder is empty
 
QUESTION
 
What is the correct way to make /user/data/ writable by LUA resident scripts?
 
OR
 
What is the recommended directory for storing user data files that:
1. Can be written to by LUA scripts
2. Can be read via HTTP by JavaScript (fetch API)
3. Persists across reboots (not /tmp/)
4. Is accessible via FTP for backup purposes
 
Any guidance would be greatly appreciated!

Code:
str = '123123123'
log(io.writefile('/home/ftp/'..os.date()..'.csv', '123123123')) 

this will write file to local ftp server, access with user ftp
Reply
#3
Correct path is /www/user/ not /user/. But a better approach is to put data into storage and use .lp files for fetching it.
Reply


Forum Jump: