# Download a url (with a password)

**URL:** <https://discourse.julialang.org/t/download-a-url-with-a-password/93669>\
**Category:** New to Julia\
**Created:** [January 27, 2023, 11:07pm UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669 "2023-01-27T23:07:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [January 27, 2023, 11:07pm UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/1 "2023-01-27T23:07:44Z")

</div>

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

```matlab
url = 'https://n5eil01u.ecs.nsidc.org/DP4/ICEBRIDGE/IRMCR2.001/2010.03.24/IRMCR2_20100324_01.csv';
urlread(url,'Username','chadagreene','Password','notactuallymypassword')

```

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?

---

<div class="post-metadata">

**Author:** ![x13420x](https://avatars.discourse-cdn.com/v4/letter/x/ecc23a/32.png) [@x13420x](https://discourse.julialang.org/u/x13420x)\
**Post date:** [January 27, 2023, 11:48pm UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/2 "2023-01-27T23:48:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 28, 2023, 2:38am UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/3 "2023-01-28T02:38:00Z")

</div>

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

```julia
using Downloads: download
file = download(url)

```

You can create a [`~/.netrc` file](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) with a username and password. You can also put the username and password in the URL.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 28, 2023, 3:06am UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/4 "2023-01-28T03:06:47Z")

</div>

> [@StefanKarpinski](#):
>
> You can also put the username and password in the URL.

In particular, see [http - How to add login credentials to URL - Stack Overflow](https://stackoverflow.com/questions/50528467/how-to-add-login-credentials-to-url)

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [January 28, 2023, 3:29am UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/5 "2023-01-28T03:29:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 30, 2023, 4:46pm UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/6 "2023-01-30T16:46:16Z")

</div>

6 posts were split to a new topic: [Download with password (digression)](https://discourse.julialang.org/t/download-with-password-digression/93783)

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [January 28, 2023, 4:30pm UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/9 "2023-01-28T16:30:49Z")

</div>

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

```julia
url = 'https://n5eil01u.ecs.nsidc.org/DP4/ICEBRIDGE/IRMCR2.001/2010.03.24/IRMCR2_20100324_01.csv';
urlread(url,'Username','chadagreene','Password','notactuallymypassword')

```

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.

---

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [January 31, 2023, 1:03am UTC](https://discourse.julialang.org/t/download-a-url-with-a-password/93669/10 "2023-01-31T01:03:25Z")

</div>

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

> <https://github.com/evetion/SpaceLiDAR.jl/blob/688105ed50c71e9d8d02c52c7a83801da1728611/src/utils.jl#L122>

This file will allow NASA EarthData and DAACs to authenticate
