{"record":{"id":"39fd9e0f937ba523","repo":"hashicorp/packer","slug":"error-uploading-script-s","errorCode":null,"errorMessage":"Error uploading script: %s","messagePattern":"Error uploading script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":394,"sourceCode":"\t\t}\n\t\tdefer f.Close()\n\n\t\tcommand, err := p.createCommandText()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error processing command: %s\", err)\n\t\t}\n\n\t\t// Upload the file and run the command. Do this in the context of a\n\t\t// single retryable function so that we don't end up with the case\n\t\t// that the upload succeeded, a restart is initiated, and then the\n\t\t// command is executed but the file doesn't exist any longer.\n\t\tvar cmd *packersdk.RemoteCmd\n\t\terr = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\t\tif _, err := f.Seek(0, 0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif err := comm.Upload(p.config.RemotePath, f, &fi); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Error uploading script: %s\", err)\n\t\t\t}\n\n\t\t\tcmd = &packersdk.RemoteCmd{Command: command}\n\t\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Close the original file since we copied it\n\t\tf.Close()\n\n\t\t// Record every other uploaded script file so we can clean it up later\n\t\tuploadedScripts = append(uploadedScripts, p.config.RemotePath)\n\n\t\tlog.Printf(\"%s returned with exit code %d\", p.config.RemotePath, cmd.ExitStatus())\n\t\tif err := p.config.ValidExitCode(cmd.ExitStatus()); err != nil {\n\t\t\treturn err","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L376-L412","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check guest connectivity and that the SSH/WinRM service stayed up during the build; fix any reboot or network instability.","Verify the remote_path directory exists and is writable by the connecting user on the guest.","Check free disk space on the guest where remote_path lands.","Increase start_retry_timeout so transient outages are retried longer.","If uploads consistently fail, test the communicator (e.g. ssh -vv / WinRM logs) to identify protocol-level problems."],"exampleFix":"// before\n\"start_retry_timeout\": \"5m\"\n// after (allow longer retries for flaky guests)\n\"start_retry_timeout\": \"15m\"","handlingStrategy":"retry","validationCode":"// before building: verify guest reachability and writable remote path\nssh user@host \"test -w $(dirname /path/to/remote) && df -h $(dirname /path/to/remote)\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the guest powered on for the whole provision phase; disable auto-reboot during builds.","Set start_retry_timeout generously for flaky guests.","Pre-create and permission the remote_path directory in the image.","Monitor guest disk space before long builds."],"tags":["network","upload","provisioner","powershell"],"backgroundTag":"communicator-upload-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}