CodeSampleX

Sample

github.com/pkg/sftp v1.10.1: Client

Verified sample for golang github.com/pkg/sftp v1.10.1: Client. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:4369bf5c6bd6dba8c1398521b90329fbb5c248965e57f76c558a8a0c4d9b7a42

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-20

Case

HOW
Goal
verify github.com/pkg/sftp.Client in pkg:golang/github.com/pkg/sftp@v1.10.1
Packages
Symbols
  • github.com/pkg/sftp.Client
Created
2026-10-20T14:01:14Z

Contract

  1. sftp.NewClientPipe(rd, wr, sftp.MaxPacket(32768)) returns a connected *sftp.Client over an in-memory net.Pipe paired with sftp.NewRequestServer(conn, sftp.InMemHandler())
  2. Client.Mkdir("/data") and Client.Create("/data/hello.txt") create a directory and remote file whose written payload is persisted in the server handler
  3. Client.Stat("/data/hello.txt") returns os.FileInfo with Name() == "hello.txt", Size() == 17, and IsDir() == false
  4. Client.Open("/data/hello.txt") reads back the exact bytes written and Client.ReadDir("/data") lists the file entry
  5. Client.Rename("/data/hello.txt", "/data/renamed.txt"), Client.Lstat("/data/renamed.txt"), and Client.Remove("/data/renamed.txt") rename, inspect, and delete the file so a subsequent Client.Stat reports os.IsNotExist(err) == true

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/pkg/sftp.Client in pkg:golang/github.com/pkg/sftp@v1.10.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/pkg/sftp@v1.10.1
Demonstrate these symbols/APIs:
  - github.com/pkg/sftp.Client

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:03d948deba54d8e9d9ff12ffc6d09bb9c6219e65795a2ab21d4aa00d3ff383b9","contract":["sftp.NewClientPipe(rd, wr, sftp.MaxPacket(32768)) returns a connected *sftp.Client over an in-memory net.Pipe paired with sftp.NewRequestServer(conn, sftp.InMemHandler())","Client.Mkdir(\"/data\") and Client.Create(\"/data/hello.txt\") create a directory and remote file whose written payload is persisted in the server handler","Client.Stat(\"/data/hello.txt\") returns os.FileInfo with Name() == \"hello.txt\", Size() == 17, and IsDir() == false","Client.Open(\"/data/hello.txt\") reads back the exact bytes written and Client.ReadDir(\"/data\") lists the file entry","Client.Rename(\"/data/hello.txt\", \"/data/renamed.txt\"), Client.Lstat(\"/data/renamed.txt\"), and Client.Remove(\"/data/renamed.txt\") rename, inspect, and delete the file so a subsequent Client.Stat reports os.IsNotExist(err) == true"],"goal":"verify github.com/pkg/sftp.Client in pkg:golang/github.com/pkg/sftp@v1.10.1","kind":"HOW","packages":["pkg:golang/github.com/pkg/sftp@v1.10.1"],"schemaVersion":1,"symbols":["github.com/pkg/sftp.Client"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/pkg/sftp@v1.10.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/pkg/sftp@v1.10.1","symbols":["github.com/pkg/sftp.Client"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.20

require github.com/pkg/sftp v1.10.1

require (
	github.com/kr/fs v0.1.0 // indirect
	github.com/pkg/errors v0.8.1 // indirect
	golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect
	golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/pkg/sftp.Client in pkg:golang/github.com/pkg/sftp@v1.10.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/pkg/sftp@v1.10.1"
  ],
  "symbols": [
    "github.com/pkg/sftp.Client"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"net"
	"os"

	"github.com/pkg/sftp"
)

func assert(cond bool, msg string) {
	if !cond {
		fmt.Fprintln(os.Stderr, "assertion failed:", msg)
		os.Exit(1)
	}
}

func main() {
	serverConn, clientConn := net.Pipe()
	defer serverConn.Close()
	defer clientConn.Close()

	server := sftp.NewRequestServer(serverConn, sftp.InMemHandler())
	serverDone := make(chan error, 1)
	go func() {
		serverDone <- server.Serve()
	}()

	var client *sftp.Client
	var err error
	client, err = sftp.NewClientPipe(clientConn, clientConn, sftp.MaxPacket(32768))
	assert(err == nil && client != nil, "NewClientPipe creates an sftp.Client")

	// 1. Mkdir and Create/Write file via sftp.Client
	err = client.Mkdir("/data")
	assert(err == nil, "Client.Mkdir creates directory /data")

	f, err := client.Create("/data/hello.txt")
	assert(err == nil && f != nil, "Client.Create opens remote file for writing")

	payload := []byte("hello sftp client")
	n, err := f.Write(payload)
	assert(err == nil && n == len(payload), "File.Write writes full payload")
	assert(f.Close() == nil, "File.Close succeeds after write")

	// 2. Stat and Open/Read via sftp.Client
	info, err := client.Stat("/data/hello.txt")
	assert(err == nil, "Client.Stat succeeds on created file")
	assert(info.Name() == "hello.txt", "Client.Stat returns expected base name")
	assert(info.Size() == int64(len(payload)), "Client.Stat returns expected file size")
	assert(!info.IsDir(), "Client.Stat reports regular file")

	rf, err := client.Open("/data/hello.txt")
	assert(err == nil && rf != nil, "Client.Open opens existing remote file")
	readBack, err := ioutil.ReadAll(rf)
	assert(err == nil && string(readBack) == string(payload), "Client.Open reads back exact file contents")
	assert(rf.Close() == nil, "File.Close succeeds after read")

	// 3. ReadDir, Rename, Lstat, Remove via sftp.Client
	entries, err := client.ReadDir("/data")
	assert(err == nil && len(entries) == 1 && entries[0].Name() == "hello.txt", "Client.ReadDir lists directory entries")

	err = client.Rename("/data/hello.txt", "/data/renamed.txt")
	assert(err == nil, "Client.Rename renames remote file")

	linfo, err := client.Lstat("/data/renamed.txt")
	assert(err == nil && linfo.Size() == int64(len(payload)), "Client.Lstat finds renamed file")

	err = client.Remove("/data/renamed.txt")
	assert(err == nil, "Client.Remove deletes remote file")

	_, err = client.Stat("/data/renamed.txt")
	assert(os.IsNotExist(err), "Client.Stat returns os.ErrNotExist after Remove")

	// 4. Close client and verify server shuts down cleanly
	assert(client.Close() == nil, "Client.Close closes session cleanly")
	srvErr := <-serverDone
	assert(srvErr == nil || srvErr == io.EOF, "RequestServer.Serve finishes cleanly on client close")
}

Origin Seeder

anonymous