Copy a directory from remote location in windows

934 views Asked by At

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 . ??

1

There are 1 answers

0
Tensibai On

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