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, err

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the file exists on the remote host at the exact path (ls -l <path> as the SSH user).
  2. Fix permissions or use an SSH user with read access to the file.
  3. Verify the vfs path string in your command/config for typos (host, user, path).
  4. 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

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


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/f79fd0df13e8de4e. Report an issue: GitHub.