func (s *StepConnectWinRM) waitForWinRM(state multistep.StateBag, cancel <-chan struct{}) (packer.Communicator, error) {
	var comm packer.Communicator
	for {
		select {
		case <-cancel:
			log.Println("WinRM wait cancelled. Exiting loop.")
			return nil, errors.New("WinRM wait cancelled")
		case <-time.After(5 * time.Second):
		}

		address, err := s.WinRMAddress(state)
		if err != nil {
			log.Printf("Error getting WinRM address: %s", err)
			continue
		}

		endpoint, err := newEndpoint(address)
		if err != nil {
			log.Printf("Incorrect format for WinRM address: %s", err)
			continue
		}

		log.Printf("Attempting WinRM connection (timeout: %s)", s.WinRMWaitTimeout)

		comm, err = plugin.New(endpoint, s.WinRMUser, s.WinRMPassword, s.WinRMWaitTimeout)
		if err != nil {
			log.Printf("WinRM connection err: %s", err)
			continue
		}

		break
	}

	return comm, nil
}
func (f *DirCommand) Run(args []string) {
	endpoint := &winrm.Endpoint{Host: *host, Port: *port}
	communicator, _ := plugin.New(endpoint, *user, *pass, *timeout)

	_, err := os.Stat(*f.from)
	if err != nil {
		log.Panicln("unable to stat dir", err.Error())
	}

	err = communicator.UploadDir(*f.to, *f.from, nil)
	if err != nil {
		log.Printf("unable to copy dir: %s", err)
	}
}
func (f *FileCommand) Run(args []string) {
	endpoint := &winrm.Endpoint{Host: *host, Port: *port}
	communicator, err := plugin.New(endpoint, *user, *pass, *timeout)

	info, err := os.Stat(*f.from)
	if err != nil {
		log.Panicln("unable to stat file", err.Error())
	}

	file, err := os.Open(*f.from)
	if err != nil {
		log.Panicln("unable to open file", err.Error())
	}

	err = communicator.Upload(*f.to, file, &info)
	if err != nil {
		log.Printf("unable to copy file: %s", err)
	}
}
func (r *RunCommand) Run(args []string) {
	command := args[0]

	endpoint := &winrm.Endpoint{Host: *host, Port: *port}
	communicator, err := plugin.New(endpoint, *user, *pass, *timeout)
	rc := &packer.RemoteCmd{
		Command: command,
		Stdout:  os.Stdout,
		Stderr:  os.Stderr,
	}
	if err != nil {
		log.Printf("unable to run command: %s", err)
		return
	}

	err = communicator.Start(rc)
	if err != nil {
		log.Printf("unable to run command: %s", err)
		return
	}

	rc.Wait()
}