Download a url (with a password)

How do I download a file from a URL, if a username and password are required? For example, in MATLAB, I can do

url = '';

and that saves a file called IRMCR2_20100324_01.csv to my local directory. That’s exactly what I want. Now how do I do it in Julia?

This post was temporarily hidden by the community for possibly being off-topic, inappropriate, or spammy.

Better to use Downloads which is a standard library. Something like

using Downloads: download
file = download(url)

You can create a ~/.netrc file with a username and password. You can also put the username and password in the URL.


In particular, see http - How to add login credentials to URL - Stack Overflow

Please do not post code generated with ChatGTP if you have not tested it (it may be correct, incorrect or not even valid julia). The good thing about this forum is that actual julia users share their knowledge and experience.


6 posts were split to a new topic: Download with password (digression)

Another security-related item that isn’t explicitly mentioned yet but definitely deserves a mention is that if you make a call like

url = '';

then that line is going to be stored in your REPL history (in any language). So at a bare minimum you should be using some external file to store passwords and keys and load those programmatically.


@chadagreene in the SpaceLiDAR.jl package we write a .netrc file using this function:

This file will allow NASA EarthData and DAACs to authenticate