kubernetes/kops · error
error opening file %s over sftp: %w
Error message
error opening file %s over sftp: %w
What it means
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.
Source
Thrown at util/pkg/vfs/sshfs.go:313
return nil, err
}
return b.Bytes(), nil
}
// WriteTo reads the file (in a streaming way)
// This implements io.WriterTo
func (p *SSHPath) WriteTo(out io.Writer) (int64, error) {
ctx := context.TODO()
sftpClient, err := p.newClient(ctx)
if err != nil {
return 0, fmt.Errorf("error creating sftp client: %w", err)
}
defer sftpClient.Close()
f, err := sftpClient.Open(p.path)
if err != nil {
return 0, fmt.Errorf("error opening file %s over sftp: %w", p, err)
}
defer f.Close()
return f.WriteTo(out)
}
func (p *SSHPath) ReadDir() ([]Path, error) {
ctx := context.TODO()
sftpClient, err := p.newClient(ctx)
if err != nil {
return nil, err
}
defer sftpClient.Close()
files, err := sftpClient.ReadDir(p.path)
if err != nil {
return nil, errView on GitHub (pinned to 4c8573c808)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Verify the remote file exists before reading over SFTP
out, err := exec.Command("ssh", host, "test -f "+remotePath+" && echo OK").Output()
if err != nil || string(out) != "OK\n" {
return fmt.Errorf("remote file %s missing or unreadable on %s", remotePath, host)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- error creating sftp client: %w
- error creating sftp client (in new-session): %w
- error creating sftp client (at stdin pipe): %w
- error reading addons from %q: %v
- error loading configuration %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/f79fd0df13e8de4e.
Report an issue: GitHub.