# Copy files from file resource to target folder

**URL:** <https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890>\
**Category:** Chef Infra (archive)\
**Created:** [November 8, 2017, 1:10am UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890 "2017-11-08T01:10:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prash](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@prash](https://discourse.chef.io/u/prash)\
**Post date:** [November 8, 2017, 1:10am UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/1 "2017-11-08T01:10:08Z")

</div>

Greetings professionals

Can any one please help me how share a directory from cookbook\_file resource to target windows server exact path

I am trying to install **Appdymanics machine agent windows version** , there is no setup.exe file available we need to copy the entire directory to remote server to target path and run the VB script which installs appd agent.

i have copied the appd directory to my cookbook\_file directory and trying to push that to target path which is C:\Program Files (x86) but unable to do it , when ever i tried to bootstrap the windows node i could able to see cookbook\_file under path C:\chef\cache\cookbooks\appd-windows

I tried using windows commands in the recipe to move folder from default path to target path but it fails  
below is the recipe im using

windows\_package ‘appdynamics’ do  
source 'file:///C:/chef/cache/cookbooks/appd-windows  
action :nothing  
end

execute ‘appd-windows’ do  
command ’ C:\chef\cache\cookbooks\appd-windows\>move C:\Program Files (x86)’ #/E’  
end

Please help…!

Thanks  
prash

---

<div class="post-metadata">

**Author:** ![Pcguy88](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@Pcguy88](https://discourse.chef.io/u/Pcguy88)\
**Post date:** [November 8, 2017, 2:00pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/2 "2017-11-08T14:00:58Z")

</div>

Good morning Prash,

Here is the logic I use to install and configure the AppDynamics agent.

# Create AppD template file

cookbook\_file "#{node['serverInfo']['tools\_dir']}/appd\_template.xml" do  
source "\_appd\_template.xml"  
action :create  
end

cookbook\_file "#{node['serverInfo']['tools\_dir']}\dotNetAgentSetup.msi" do  
source 'dotNetAgentSetup.msi'  
action :create  
end

# Install AppDynamics Agent

windows\_package 'appdynamics' do  
action :install  
source "#{node['serverInfo']['tools\_dir']}\dotNetAgentSetup.msi"  
options "/q /norestart /lv "#{node['serverInfo']['tools\_dir']}\AgentInstaller.log" AD\_SetupFile="#{node['serverInfo']['tools\_dir']}\appd\_template.xml""  
end

the node[‘serverInfo’][‘tools\_dir’] is an attribute I define that points to a local path on a server where we keep installer files and various tools for administrative use.

So basically I store the current AppD installer file and various AppD template files in my cookbook, I copy both down to the server and then use the windows\_package resource to install and configure it.

Brian

![](https://sea2.discourse-cdn.com/flex016/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![joerg.herzinger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joerg.herzinger/32/1514_2.png) [@joerg.herzinger](https://discourse.chef.io/u/joerg.herzinger)\
**Post date:** [November 8, 2017, 3:59pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/3 "2017-11-08T15:59:36Z")

</div>

Just as a side note: Cookbooks are not supposed to be file storages and the Chef Server is not optimized to server large binary files. You will run into massive troubles quite soon if you really store MSI or any other large files in your cookbooks.  
You should use Artifactory or similar for that or at least keep the files on a File share.

---

<div class="post-metadata">

**Author:** ![shirisha](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@shirisha](https://discourse.chef.io/u/shirisha)\
**Post date:** [October 26, 2018, 2:24pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/4 "2018-10-26T14:24:59Z")

</div>

You have a sample of how to do that? Tried but failed.

remote\_file 'copyfile2' do  
atomic\_update false  
source 'file:////mysharechef\_file\_create.ps1'  
path 'c:/temp/chef\_file\_create.ps1'  
end

---

<div class="post-metadata">

**Author:** ![prash](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@prash](https://discourse.chef.io/u/prash)\
**Post date:** [October 26, 2018, 6:52pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/5 "2018-10-26T18:52:51Z")

</div>

windows\_package 'WindowsSensor' do  
source 'file:///C:/chef/cache/cookbooks/CrowdStrike-windows/files/default/WindowsSensor.exe'  
options "/install /quiet /norestart "  
installer\_type :msi  
action :install  
end

---

<div class="post-metadata">

**Author:** ![prash](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@prash](https://discourse.chef.io/u/prash)\
**Post date:** [October 26, 2018, 6:55pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/6 "2018-10-26T18:55:17Z")

</div>

This is how i copied the file or dir from source to remote location...

---

<div class="post-metadata">

**Author:** ![shirisha](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@shirisha](https://discourse.chef.io/u/shirisha)\
**Post date:** [October 26, 2018, 8:43pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/7 "2018-10-26T20:43:59Z")

</div>

Doesnt look like that file in windows share. windows\_package , is that dependent on any other libraries?

---

<div class="post-metadata">

**Author:** ![shirisha](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@shirisha](https://discourse.chef.io/u/shirisha)\
**Post date:** [October 26, 2018, 9:23pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/8 "2018-10-26T21:23:28Z")

</div>

tried this windows\_package '7zip' do  
source '[http://www.7-zip.org/a/7z938-x64.msi](http://www.7-zip.org/a/7z938-x64.msi)'  
action :install  
end  
but failed  
Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - Connection refused connecting to [http://www.7-zip.org/a/7z938-x64.msi](http://www.7-zip.org/a/7z938-x64.msi), giving up

---

<div class="post-metadata">

**Author:** ![prash](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@prash](https://discourse.chef.io/u/prash)\
**Post date:** [October 26, 2018, 9:54pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/9 "2018-10-26T21:54:09Z")

</div>

No it is under files directory under the custom cookbook

---

<div class="post-metadata">

**Author:** ![shirisha](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@shirisha](https://discourse.chef.io/u/shirisha)\
**Post date:** [October 26, 2018, 10:21pm UTC](https://discourse.chef.io/t/copy-files-from-file-resource-to-target-folder/11890/10 "2018-10-26T22:21:15Z")

</div>

We have large msi files and cannot store those with cookbook\_name/files. However did try a simple bat file and it did copy. Any other ideas?
