# get\_url - counterintuitive that it re-downloads if "dest" is a directory

**URL:** <https://forum.ansible.com/t/get-url-counterintuitive-that-it-re-downloads-if-dest-is-a-directory/15248>\
**Category:** Ansible Developer\
**Created:** [May 15, 2014, 4:59pm UTC](https://forum.ansible.com/t/get-url-counterintuitive-that-it-re-downloads-if-dest-is-a-directory/15248 "2014-05-15T16:59:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edrozenberg](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@edrozenberg](https://forum.ansible.com/u/edrozenberg)\
**Post date:** [May 15, 2014, 4:59pm UTC](https://forum.ansible.com/t/get-url-counterintuitive-that-it-re-downloads-if-dest-is-a-directory/15248/1 "2014-05-15T16:59:32Z")

</div>

Hello,

I noticed that my get\_url calls were taking a long time even if the file  
was already downloaded. After digging in the docs I found the following:

“If dest is a directory, the file will always be downloaded (regardless of the force option), but replaced only if the contents changed.”

IMO this is unintuitive because it should not matter whether the destination is a filename or directory. The situation is the same -  
a file by that same name exists in a particular directory. Therefore the behavior should be the same, and controlled by other flags.

It would also be great if there were a way to compare checksums without downloading a file first - not sure  
it’s possible but currently a large file would need to be downloaded first in order to check if it is identical to a  
target - far from ideal given bandwidth and time constraints.

Regards,  
–Ed

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [May 15, 2014, 6:05pm UTC](https://forum.ansible.com/t/get-url-counterintuitive-that-it-re-downloads-if-dest-is-a-directory/15248/2 "2014-05-15T18:05:29Z")

</div>

The issue is because you cannot know the hash of the file remotely, and when the destination is a directory the filename that is being written to is extracted from the headers of the response - so a request has to be made. I suppose that could be tweaked to do a HEAD call first, and only do the full GET request if the filename can’t be determined. If you’d like to open a github issue for that, feel free.

---

<div class="post-metadata">

**Author:** ![edrozenberg](https://avatars.discourse-cdn.com/v4/letter/e/a6a055/32.png) [@edrozenberg](https://forum.ansible.com/u/edrozenberg)\
**Post date:** [May 15, 2014, 6:29pm UTC](https://forum.ansible.com/t/get-url-counterintuitive-that-it-re-downloads-if-dest-is-a-directory/15248/3 "2014-05-15T18:29:07Z")

</div>

James - thanks for the explanation. I have created [https://github.com/ansible/ansible/issues/7424](https://github.com/ansible/ansible/issues/7424)  
I think a HEAD call to get the filename first and avoid a full re-download makes a lot of sense.

Regards,  
–Ed
