MATLAB Answers

Can I import dynamic data from a private server into Matlab?

7 views (last 30 days)
Enric Astals
Enric Astals on 9 Mar 2020
Commented: Guillaume on 11 Mar 2020
Hello,
I am currently writing some code in Matlab to process data from a private server (with private I mean that every time I login, it asks me for the password). To do so, I have been downloading the data everyday into .csv files.
The data on the server is updated every minute.
Is there a way to connect Matlab to the private server, give Matlab the power to remember the password (or override it) and, when the code runs, to collect all updated data?
Thank you very much.
Sidenote: I am at a pretty basic level of Matlab.

  4 Comments

Show 1 older comment
Enric Astals
Enric Astals on 9 Mar 2020
Thanks for the re-direct. In these options that are stated in the other answer, do I only have to modify the following: Key_name, Key_value, token and xxx? Or does it require to change more stuff?
Thanks again.
Turlough Hughes
Turlough Hughes on 9 Mar 2020
Try what Guillaume suggested. Let us know if you have any errors coming back.

Sign in to comment.

Answers (2)

Guillaume
Guillaume on 9 Mar 2020
How easy this is to do is going to depend on the server (how it is implemented). You would use one of webread, webwrite or websave.
Assuming your server is fully REST compatible, and it uses basic or digest authentication, accessing your data may be as easy as:
url = 'https://yourprivateserver/somelocation/somefile.csv';
username = 'yourusername';
password = 'secret'; %note that if write it in an m file, anybody who has access to the m file can read your password
data = webread(url, weboptions('Username', username, 'Password', password));

  0 Comments

Sign in to comment.


Enric Astals
Enric Astals on 10 Mar 2020
Hi, thank you for both your answers. I tried what you recommended, but got these errors, which are the same errors I got trying what the other thread recommended.
I'll attach the error in the following lines, only modifying the password for mypassword.
>> Untitled
Error using weboptions
'db_ciment' is not a recognized parameter. For a list of valid name-value pair arguments, see the
documentation for weboptions.
Error in weboptions>parseInputs (line 529)
p.parse(args{:});
Error in weboptions (line 301)
inputs = parseInputs(options, varargin);
Error in Untitled (line 4)
data = webread(url, weboptions('db_ciment', username, 'mypassword', password));

  3 Comments

Turlough Hughes
Turlough Hughes on 10 Mar 2020
In the example Guillaume provided you are supposed to modify the first three lines and not the last one.
Enric Astals
Enric Astals on 11 Mar 2020
I see! Thank you.
I now only obtain one error, which seems to be due to a 'unexpected expression' of the password. Do you know if it is problematic for the password to contain numbers, letters and caps?
Guillaume
Guillaume on 11 Mar 2020
Can you give us the full text of the error message so we can understand if it comes from matlab or your server?
Matlab does no check at all on the content of the password, it just passes it to the server. However, it sounds like you have a syntax error.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!