{"record":{"id":"f79fd0df13e8de4e","repo":"kubernetes/kops","slug":"error-opening-file-s-over-sftp-w","errorCode":null,"errorMessage":"error opening file %s over sftp: %w","messagePattern":"error opening file (.+?) over sftp: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/sshfs.go","lineNumber":313,"sourceCode":"\t\treturn nil, err\n\t}\n\treturn b.Bytes(), nil\n}\n\n// WriteTo reads the file (in a streaming way)\n// This implements io.WriterTo\nfunc (p *SSHPath) WriteTo(out io.Writer) (int64, error) {\n\tctx := context.TODO()\n\n\tsftpClient, err := p.newClient(ctx)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"error creating sftp client: %w\", err)\n\t}\n\tdefer sftpClient.Close()\n\n\tf, err := sftpClient.Open(p.path)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"error opening file %s over sftp: %w\", p, err)\n\t}\n\tdefer f.Close()\n\n\treturn f.WriteTo(out)\n}\n\nfunc (p *SSHPath) ReadDir() ([]Path, error) {\n\tctx := context.TODO()\n\n\tsftpClient, err := p.newClient(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer sftpClient.Close()\n\n\tfiles, err := sftpClient.ReadDir(p.path)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/sshfs.go#L295-L331","documentation":"After a successful SFTP session is established, WriteTo opens the remote file at p.path via sftpClient.Open. If the file cannot be opened (does not exist, permission denied, path is a directory), the error is wrapped as 'error opening file %s over sftp' with the full path and underlying cause.","triggerScenarios":"ReadFile/WriteTo on an sshfs:// path whose remote file is missing, has restrictive permissions for the SSH user, or the path component is a directory.","commonSituations":"Typo in the remote manifest/manifest path, reading a cluster state file the SSH user cannot access, or the remote file was deleted/moved between calls.","solutions":["Check the file exists on the remote host at the exact path (ls -l <path> as the SSH user).","Fix permissions or use an SSH user with read access to the file.","Verify the vfs path string in your command/config for typos (host, user, path).","Review the wrapped cause (%w) — 'file does not exist' vs 'permission denied' dictates the fix."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the remote file exists before reading over SFTP\nout, err := exec.Command(\"ssh\", host, \"test -f \"+remotePath+\" && echo OK\").Output()\nif err != nil || string(out) != \"OK\\n\" {\n\treturn fmt.Errorf(\"remote file %s missing or unreadable on %s\", remotePath, host)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm exact remote path with ls before scripting reads","Ensure the SSH user has read permission on the state files","Avoid typos in sshfs:// path strings; use tab-completion or variables","Watch for files deleted by concurrent jobs between calls"],"tags":["ssh","sftp","file-not-found","vfs"],"backgroundTag":"file-open-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}