{"record":{"id":"53bb9dfa8b5a999c","repo":"hashicorp/packer","slug":"error-uploading-script-s-53bb9d","errorCode":null,"errorMessage":"Error uploading script: %s","messagePattern":"Error uploading script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":335,"sourceCode":"\n\t\t// Upload the file and run the command. Do this in the context of\n\t\t// a single retryable function so that we don't end up with\n\t\t// the case that the upload succeeded, a restart is initiated,\n\t\t// and then the command is executed but the file doesn't exist\n\t\t// 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\n\t\t\tvar r io.Reader = f\n\t\t\tif !p.config.Binary {\n\t\t\t\tr = &UnixReader{Reader: r}\n\t\t\t}\n\n\t\t\tif err := comm.Upload(p.config.RemotePath, r, nil); 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{\n\t\t\t\tCommand: fmt.Sprintf(\"chmod 0755 %s\", p.config.RemotePath),\n\t\t\t}\n\t\t\tif err := comm.Start(ctx, cmd); err != nil {\n\t\t\t\treturn fmt.Errorf(\n\t\t\t\t\t\"Error chmodding script file to 0755 in remote \"+\n\t\t\t\t\t\t\"machine: %s\", err)\n\t\t\t}\n\t\t\tcmd.Wait()\n\n\t\t\tcmd = &packersdk.RemoteCmd{Command: command}\n\t\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t\t})\n\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L317-L353","documentation":"The provisioner uploads the script to the remote machine at config.RemotePath via the communicator (SSH/WinRM/Docker). If comm.Upload fails — connection dropped, permission denied, disk full, path not writable — Provision returns this error inside the retryable StartRetryTimeout loop. Because the upload is retried, transient disconnects are retried until the timeout is exhausted.","triggerScenarios":"comm.Upload(p.config.RemotePath, r, nil) returning an error: SSH/WinRM connection failure mid-upload, remote path not writable (e.g. /tmp full or root-only), authentication failure, or remote host unreachable during provisioning.","commonSituations":"Remote machine rebooted by a previous provisioner so the connection is gone; /tmp on the instance full; SSH key rotated or agent disconnected; Windows communicators failing on path semantics for RemotePath; flaky network to a cloud VM.","solutions":["Verify the communicator connection is alive (ssh/winrm credentials, security groups, network ACLs)","Check the remote path is writable and the filesystem has space (e.g. /tmp not full)","Increase start_retry_timeout if the failure is transient during reboots","Re-run the build; if it follows a rebooting provisioner, order it after restart completion or use expect_disconnect/retry logic"],"exampleFix":"// before (packer template)\nprovisioner \"shell\" {\n  remote_path = \"/root/not-writable/script.sh\"\n}\n// after\nprovisioner \"shell\" {\n  remote_path = \"/tmp/script.sh\"\n  start_retry_timeout = \"10m\"\n}","handlingStrategy":"retry","validationCode":"# Before building, verify communicator reachability:\nssh -i key.pem user@host 'test -w /tmp && df -h /tmp'   # writable path + free space","typeGuard":null,"tryCatchPattern":"err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n    if _, err := f.Seek(0, 0); err != nil { return err }\n    if err := comm.Upload(p.config.RemotePath, r, nil); err != nil {\n        return fmt.Errorf(\"Error uploading script: %s\", err)\n    }\n    return nil\n})","preventionTips":["Point remote_path at a writable, space-available directory like /tmp","Increase start_retry_timeout when builds follow rebooting provisioners","Verify SSH/WinRM credentials, ports, and security-group rules before long builds","Avoid overlapping provisioners that reboot the machine mid-upload"],"tags":["provisioner","shell","upload","communicator","ssh"],"backgroundTag":"file-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"}