hashicorp/packer · error

Error uploading script: %s

Error message

Error uploading script: %s

What it means

The PowerShell provisioner uploads the generated script to the remote machine via the communicator inside a retry loop (retry.Config with StartRetryTimeout). This error wraps any failure returned by comm.Upload, such as SFTP/SCP protocol errors or connection drops. The retry loop will keep re-attempting the upload (seeking the file back to offset 0 each time) until StartRetryTimeout expires, then surface this wrapped message. It means the script file never reached the guest, so the provisioner cannot execute it.

Source

Thrown at provisioner/powershell/provisioner.go:394

		}
		defer f.Close()

		command, err := p.createCommandText()
		if err != nil {
			return fmt.Errorf("Error processing command: %s", err)
		}

		// Upload the file and run the command. Do this in the context of a
		// single retryable function so that we don't end up with the case
		// that the upload succeeded, a restart is initiated, and then the
		// command is executed but the file doesn't exist any longer.
		var cmd *packersdk.RemoteCmd
		err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {
			if _, err := f.Seek(0, 0); err != nil {
				return err
			}
			if err := comm.Upload(p.config.RemotePath, f, &fi); err != nil {
				return fmt.Errorf("Error uploading script: %s", err)
			}

			cmd = &packersdk.RemoteCmd{Command: command}
			return cmd.RunWithUi(ctx, comm, ui)
		})
		if err != nil {
			return err
		}

		// Close the original file since we copied it
		f.Close()

		// Record every other uploaded script file so we can clean it up later
		uploadedScripts = append(uploadedScripts, p.config.RemotePath)

		log.Printf("%s returned with exit code %d", p.config.RemotePath, cmd.ExitStatus())
		if err := p.config.ValidExitCode(cmd.ExitStatus()); err != nil {
			return err

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Check guest connectivity and that the SSH/WinRM service stayed up during the build; fix any reboot or network instability.
  2. Verify the remote_path directory exists and is writable by the connecting user on the guest.
  3. Check free disk space on the guest where remote_path lands.
  4. Increase start_retry_timeout so transient outages are retried longer.
  5. If uploads consistently fail, test the communicator (e.g. ssh -vv / WinRM logs) to identify protocol-level problems.

Example fix

// before
"start_retry_timeout": "5m"
// after (allow longer retries for flaky guests)
"start_retry_timeout": "15m"
Defensive patterns

Strategy: retry

Validate before calling

// before building: verify guest reachability and writable remote path
ssh user@host "test -w $(dirname /path/to/remote) && df -h $(dirname /path/to/remote)"

Prevention

When it happens

Trigger: comm.Upload returns a non-nil error while provisioning: SSH/SFTP connection reset mid-upload, guest disk full, permission denied writing to RemotePath, or the remote host rebooted during the upload retry window.

Common situations: WinRM/SSH guest briefly restarting during provisioning; remote path on a full or read-only volume; firewall dropping long-lived SFTP sessions; using a communicator whose upload implementation rejects the file size or path; temporary network flakiness in CI.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/39fd9e0f937ba523. Report an issue: GitHub.