{"record":{"id":"0760f154e3438236","repo":"hashicorp/packer","slug":"failed-to-upload-packer-binary-s","errorCode":null,"errorMessage":"failed to upload Packer binary: %s","messagePattern":"failed to upload Packer binary: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/hcp-sbom/provisioner.go","lineNumber":539,"sourceCode":"\t\t\tremoteDir, binaryName,\n\t\t\tremoteDir, binaryName, remotePath,\n\t\t\tremoteZipPath,\n\t\t)\n\t\tif err := p.runRemoteCmd(ctx, comm, psCmd, \"extract scanner (Windows)\"); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t} else {\n\t\t// Step 1: extract the binary locally from the release zip.\n\t\tbinaryData, err := extractBinaryFromZip(localZipPath, binaryName)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to extract %s from Packer release zip: %w\", binaryName, err)\n\t\t}\n\n\t\t// Step 2: upload binary directly to remote.\n\t\tlocalFile := bytes.NewReader(binaryData)\n\t\tlog.Printf(\"[INFO] Uploading Packer binary to %s...\", remotePath)\n\t\tif err := comm.Upload(remotePath, localFile, nil); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to upload Packer binary: %s\", err)\n\t\t}\n\n\t\t// Step 3: make it executable.\n\t\tchmodCmd := fmt.Sprintf(`chmod +x \"%s\"`, remotePath)\n\t\tif err := p.runRemoteCmd(ctx, comm, chmodCmd, \"chmod scanner binary\"); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\t// Final verify: confirm binary is executable.\n\t\tverifyCmd := fmt.Sprintf(`test -x \"%s\"`, remotePath)\n\t\tif err := p.runRemoteCmd(ctx, comm, verifyCmd, \"verify scanner is executable\"); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"scanner binary is not executable at %s after chmod; \"+\n\t\t\t\t\"check that /tmp is not mounted noexec on the remote host\", remotePath)\n\t\t}\n\t}\n\n\treturn remotePath, nil\n}","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/hcp-sbom/provisioner.go#L521-L557","documentation":"This error wraps a comm.Upload failure when writing the extracted scanner binary bytes to /tmp/packer-sbom-runner on the Unix guest. It is thrown at provisioner/hcp-sbom/provisioner.go:539 in uploadScanner (Unix path), called by provisionWithNativeGeneration. The zip extraction already succeeded; the failure is purely in transferring the binary over the communicator (SSH, typically), with the underlying transport error embedded.","triggerScenarios":"comm.Upload(remotePath, localFile, nil) errors in the Unix branch of uploadScanner — SSH connection dropped, auth failure, guest /tmp full or read-only, scp/sftp unavailable or disabled on the guest, or a transfer timeout.","commonSituations":"Guest's /tmp filesystem is full or mounted read-only; SSH server restricts SFTP/SCP subsystems (only shell allowed); SSH key/auth problems in the communicator config; connection drops during upload on flaky networks; disk quota exceeded for the SSH user.","solutions":["Check PACKER_LOG=1 output for the wrapped error and fix the root transport cause (auth, subsystem, disk).","Verify the guest's /tmp has free space and is writable: `df -h /tmp && touch /tmp/probe` as the SSH user.","Ensure the guest's SSH server has the sftp subsystem enabled (default sshd_config), since the communicator uploads via SFTP.","Check SSH auth in the communicator block (ssh_username, ssh_private_key_file / temporary key from the builder).","Retry the build if a transient network drop interrupted the transfer."],"exampleFix":"// before (guest sshd_config)\n#Subsystem sftp /usr/lib/openssh/sftp-server\n// after\nSubsystem sftp internal-sftp","handlingStrategy":"retry","validationCode":"// pre-flight: SSH reachability and SFTP support\nconn, err := net.DialTimeout(\"tcp\", fmt.Sprintf(\"%s:22\", guestHost), 10*time.Second)\nif err != nil {\n\treturn fmt.Errorf(\"SSH not reachable: %w\", err)\n}\nconn.Close()\n// during provisioning: ensure /tmp writable and has space\nout, err := runRemote(`df -h /tmp | tail -1`)\nif err != nil {\n\treturn fmt.Errorf(\"cannot check /tmp space: %w\", err)\n}\nlog.Printf(\"guest /tmp usage: %s\", out)","typeGuard":null,"tryCatchPattern":"err := comm.Upload(remotePath, localFile, nil)\nif err != nil {\n\tvar netErr net.Error\n\tif errors.As(err, &netErr) && netErr.Timeout() {\n\t\t// retry with backoff, or raise ssh handshake/upload timeout\n\t}\n\tif strings.Contains(err.Error(), \"sftp\") || strings.Contains(err.Error(), \"subsystem\") {\n\t\t// enable sftp subsystem on guest sshd\n\t}\n\treturn fmt.Errorf(\"failed to upload Packer binary: %w\", err)\n}","preventionTips":["Ensure the guest sshd has the sftp subsystem enabled before builds.","Verify /tmp has free space and is writable by the SSH user (add a df/touch pre-check).","Use a stable, pre-authenticated SSH key in the communicator config; avoid key rotation mid-build.","Retry transient network failures with backoff.","For flaky networks, consider uploading a smaller compressed binary and expanding remotely."],"tags":["network","upload","ssh","communicator","unix"],"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"}