# copy file from remote windows server to local machine?

**URL:** <https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 18, 2016, 4:16am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611 "2016-02-18T04:16:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 18, 2016, 4:16am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/1 "2016-02-18T04:16:34Z")

</div>

In Ansible 2.0, the win\_copy module will move a local file to a remote windows machine.

Is there an Ansible way to fetch a remote file on a windows server and move it to a local machine?

J

---

<div class="post-metadata">

**Author:** ![Gerald\_Spencer1](https://avatars.discourse-cdn.com/v4/letter/g/b782af/32.png) [@Gerald\_Spencer1](https://forum.ansible.com/u/Gerald_Spencer1)\
**Post date:** [February 18, 2016, 5:35am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/2 "2016-02-18T05:35:14Z")

</div>

[Line 85](https://github.com/ansible/ansible-modules-core/blob/8d126bd877444c9557b1671521516447cc557d3f/windows/win_copy.ps1#L85) in the win\_copy module is the chunk that actually copies the file from the local to remote. Perhaps try executing a raw command to test it out? Something along the lines of:

- name: copy to local from remote  
raw: Copy-Item -Path {{remoteFileLocation}} -Destination {{localFileLocation}} -Force

Can’t test this currently, but can do in the morning.

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 19, 2016, 7:51pm UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/3 "2016-02-19T19:51:00Z")

</div>

I think this will work but I’d have to know how to specify the destination location (my Mac laptop) in a way  
that makes sense to Powershell Remoting. I have no clue how to do that.

The very last answer to this stackoverflow demonstrates the methodology. Any Windows/PS pros in the house?

[http://stackoverflow.com/questions/9304953/copy-files-from-remote-rdp-to-local-machine](http://stackoverflow.com/questions/9304953/copy-files-from-remote-rdp-to-local-machine)

J

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 20, 2016, 6:18am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/4 "2016-02-20T06:18:08Z")

</div>

More relevant discussion: [http://stackoverflow.com/questions/10741609/copy-file-remotely-with-powershell](http://stackoverflow.com/questions/10741609/copy-file-remotely-with-powershell)

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 22, 2016, 2:49am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/5 "2016-02-22T02:49:55Z")

</div>

Anyone know what the destination format would be in Powershell to target the local desktop?

J

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 22, 2016, 8:57am UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/6 "2016-02-22T08:57:30Z")

</div>

I may be missing the point here but is the fetch module what you need? Fetch works against windows hosts and linux hosts.

Plenty of examples in the integration tests here: [https://github.com/ansible/ansible/blob/devel/test/integration/roles/test\_win\_fetch/tasks/main.yml](https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_fetch/tasks/main.yml)

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [February 22, 2016, 3:09pm UTC](https://forum.ansible.com/t/copy-file-from-remote-windows-server-to-local-machine/20611/7 "2016-02-22T15:09:28Z")

</div>

I forgot that it was mentioned in the docs. Maybe there should be an  
"alias" page in the list of "Windows" modules.

Thanks!

J
