0

what is the way to copy the entire directory from remote machine(windows) to my local machine(windows).

The methods i tried using in windows_batch resource

xcopy //machinename/foldername/* C:/  /s /e

xcopy \\machinename\foldername\* C:\  /s /e

i am getting an error saying invalid number of parameters

can some correct me out . ??

  • This doesn't seem directly related to Chef. – coderanger Sep 02 '14 at 18:29
  • Have you run the command manually? Something like `xcopy \\remote-box\tmp\something\* C:\temp /s /e` is perfectly valid, so your Chef recipe might be using the \ as an escape character unexpectedly – Display Name is missing Sep 02 '14 at 22:53
  • @castling . yes i tried manually and it worked. When i am trying in Chef i am not able to do . – Mohan Karthik Sanagapalli Sep 03 '14 at 06:42
  • It definitely works in my machine. Do your remote folder path have empty spaces? If so, add quotes to your path. Cannot think of other reasons. – Landys Sep 03 '14 at 09:20
  • @Landys no its not having any space . in the remote location the dircetory is also getting created . but its saying the source location is not "no such file or directory" where i am able to access that link. – Mohan Karthik Sanagapalli Sep 03 '14 at 10:44
  • @Landys can i use remote_directory resource for this ?? or should i use windows_batch resource for executing the copy command – Mohan Karthik Sanagapalli Sep 03 '14 at 12:42
  • @mohan Not sure what you mean by "remote_directory" resource and "windows_batch" resource? To me, it is quite straightforward that just open a command prompt, and enter the `xcopy` command. I think first you need to check it you can access `\\machinename\foldername` with windows explorer and copy files to local correctly. Then try to execute the command again and show me the exact command and error, and I'll take a further look. – Landys Sep 03 '14 at 13:52
  • @Landys yeah now its working fine in cmd prompt. but i want to automate that process now. – Mohan Karthik Sanagapalli Sep 03 '14 at 17:36

1 Answers1

0

The way I solved this is using two ressources:

1) mount to mount the remote directory

2) remote_directory from the mount point to local point

Note that the mount ressource notifies itself to unmount at end of chef run to avoid mount points staying on the servers.

Ex with remote file:

  share =  File::dirname(node['firefox']['http_url'])
  filename = File::basename(node['firefox']['http_url']) 
  ENV['tmpdrive'] = "Z:"
  mount "Z:" do
    action :mount
    device share
    username "my_user"
    domain "my_domain"
    password "xxxxxx"
    notifies :umount, "mount[Z:]"
  end

  # Wrokaround sous win2k3
#  batch "copy firefox source" do
#    command %Q{xcopy /YZE "Z/#{filename}" "#{ENV['TEMP']}/#{filename}"}.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR)
#    notifies :umount, "mount[Z:]", :immediately
#  end
  remote_file "#{ENV['TEMP']}/#{filename}" do
     source "file:///z:/#{filename}"
     notifies :umount, "mount[Z:]", :immediately
  end
Tensibai
  • 15,557
  • 1
  • 37
  • 57