{"record":{"id":"06ddc51872d3c88d","repo":"arduino/Arduino","slug":"scp-error","errorCode":null,"errorMessage":"SCP error: ","messagePattern":"SCP error: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/cc/arduino/packages/ssh/SCP.java","lineNumber":90,"sourceCode":"  private void ensureAcknowledged() throws IOException {\n    out.flush();\n\n    int b = in.read();\n\n    if (b == 0) return;\n    if (b == -1) return;\n\n    if (b == 1 || b == 2) {\n      StringBuilder sb = new StringBuilder();\n      sb.append(\"SCP error: \");\n\n      int c;\n      do {\n        c = in.read();\n        sb.append((char) c);\n      } while (c != '\\n');\n\n      throw new IOException(sb.toString());\n    }\n\n    throw new IOException(\"Uknown SCP error: \" + b);\n  }\n\n  public void sendFile(File localFile) throws IOException {\n    sendFile(localFile, localFile.getName());\n  }\n\n  public void sendFile(File localFile, String remoteFile) throws IOException {\n    out.write((\"C0644 \" + localFile.length() + \" \" + remoteFile + \"\\n\").getBytes());\n    ensureAcknowledged();\n\n    FileInputStream fis = null;\n    try {\n      fis = new FileInputStream(localFile);\n      byte[] buf = new byte[4096];\n      while (true) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/cc/arduino/packages/ssh/SCP.java#L72-L108","documentation":"Thrown by SCP.ensureAcknowledged when the remote scp process replies with a byte code it does not recognize as success (0), warning (1), or error (2), while also failing to produce a newline-terminated error message. The message includes the unexpected byte value and appears in the SSH file-upload path of Arduino IDE.","triggerScenarios":"During open/sendFile/startFolder/endFolder, the remote scp binary sends an unexpected status byte (not 0, 1, or 2) — typically caused by a shell login banner, rc-file output, or a non-standard/patched scp on the Yún-style board.","commonSituations":"Board firmware or OpenSSH versions where scp emits extra output; user shell dotfiles (.profile, .bashrc) printing text on login, which corrupts the SCP protocol stream.","solutions":["Remove echo/banner output from the board user's shell startup files (.profile, .bashrc)","Update the board's system software (OpenSSH/scp) to a standard version","Retry the upload to rule out a transient corrupted stream","Use the board's web-based upload mechanism if SSH/SCP stays unreliable"],"exampleFix":"// before (.bashrc on board)\necho \"Welcome!\"\n// after\n// remove or guard echo statements in non-interactive shells:\n[[ $- == *i* ]] && echo \"Welcome!\"","handlingStrategy":"try-catch","validationCode":"// pre-check: ensure a clean SSH channel\nProcess p = new ProcessBuilder(\"ssh\", \"root@\"+host, \"which scp\").start();\nif (p.waitFor() != 0) throw new IllegalStateException(\"scp missing on board\");","typeGuard":null,"tryCatchPattern":"try (SCP scp = new SCP(ssh)) {\n    scp.sendFile(local);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Uknown SCP error\")) {\n        // protocol corruption: clean board shell rc files, retry\n    }\n}","preventionTips":["Keep board shell rc files silent for non-interactive sessions","Keep board OpenSSH/scp stock and updated","Test with a manual scp before automated uploads"],"tags":["ssh","scp","upload","protocol"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}