How to access /web folder from FileIO for .csv file writing?

Simple problem - part of my PLC program is acting as a data logger, creating a .CSV file.
I can make the file, that is no issue.

Accessing it externally is a different matter, all customer’s PC’s have USB ports locked. I prefer not to go via the FTP route unless necessary.

I thought of sticking the .CSV files into /web folder, so they could be accessed directly from the IP address of the machine.

Can you point me how to configure the file devices in 4PPC70 so I could write to /web folder?

Thank you!

Hi,

in general, it’s more or less about using the right file device for your FileIO calls.
You could setup a own file device pointing to “F:\web” (I assume the web folder is directly located on the F: partition = User partition) by AS configuration setting or by dynamically creating the file device using FileIO FB DevLink(), or you could use the predefined file device “USER” and trying to add the folder name into your file name using in FileIO calls (e.g. filename = “web\myfile.txt”).
In the end, which way is the better one is depending on the FileIO functions you want to use.

For some more concrete suggestions, a screenshot of your code could be helpful.

Best regards.

Thank you for fast reply.
Currently this is my CPU config.

For testing I am using FTP and that (since it is pointed to USER partition), correctly sees my CSV files.

However, none of these work, so it seems web server is looking for files somewhere else.

IP_ADDRESS/test.csv
IP_ADDRESS/web/test.csv

I ran my file creation code with filename as test.csv and as web\test.csv. First worked, second does not.

Then I realized, that the function likely isn’t smart enough to autocreate folders if they do not exist, so created an internal folder “web” via FTP. After that, web\test.csv was created when I ran my saving code.

Still, this returns error 20708 (File not found), so webserver can’t access my files.
IP_ADDRESS/web/test.csv

Then I made an index.html in web\

IP_ADDRESS/index.html works
IP_ADDRESS/test.csv works

After changing webserver settings from web\ to \ I can directly access root of USER and all is well.

Final settings here, hopefully it helps someone later:

Hi,

ok, now I understand, thanks for the explanations and screenshots.
If you want to expose the whole user partition to the webserver, then it’s perfectly fine, thanks for sharing it!

I’ll try to give some more short insights for anyone else maybe needs that information:

first of all, you’re right, the system never creates any folders automatically. Even if a webroot directory is configured (it’s “\web” for default) in the CPU configuration, this folder won’t be automatically created.

Then, we have to separate 2 topics:

  • the FILE SYSTEM root of the user partition
  • the WEB root of the webserver

When you’re working with FileIO, the file system root is the user partition, which is the “F:”. There’s a predefined device named “USER” pointing to “USER_PATH” (which is “F:”).

When working with the webserver, the web root (means the “/” URI) starts inside the parametrized web root directory (which is a file system directory). But for the webserver itself, the web root directory is not known.
This is more or less a standard behavior of a webserver, every webserver lives inside some file system folder, where the webservers root “sandbox” starts. Because for administrative and security reasons, normally you won’t expose all folders / files to the webserver.

Using the default settings means:

  • There’s a F: partition, the user partition
  • the F: filesystem contains a folder “web”, which is the webservers root
  • using FileIO and the predefined “USER” device, you have to store your CSV under “web/mydata.csv”, because this access operates on file system level
  • using the webserver access via browser, you have to open “http://IPaddress/mydata.csv”, because the webserver’s root starts inside the “/web” file system directory.
  • … same for subfolders - in this example, any subfolder inside “/web” would be also accessible for the webserver, any folder outside “/web” won’t

And the last bulletpoint is exactly the reason for using a folder as the webroot: so you’re able to define a folder/subfolder structure in the filesystem, where a part of is accessible by the webserver, and all of the rest isn’t.

Hope that makes it a bit more clear for others here in the community.
Best regards!