Repository navigation
[v1] add examples of SFTP over TLS without SSH - #689
Merged
Merged
Conversation
The NewClientPipe docs say it can be used over TCP/TLS, but the only example runs the ssh command. Add a client and a server example using crypto/tls with client certificates, since SFTP has no authentication of its own, and point out that NewServer exposes the local filesystem.
puellanivis
reviewed
Oct 19, 2026
| if err := server.Serve(); err != nil && err != io.EOF { | ||
| log.Print("sftp server completed with error: ", err) | ||
| } | ||
| server.Close() |
Collaborator
Contributor
Author
There was a problem hiding this comment.
Changed the cleanup to call conn.Close() after server.Serve() returns. This closes the accepted TLS connection explicitly and makes the example’s connection cleanup clear.
Contributor
Author
|
The pipeline failure came from |
puellanivis
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

For #90.
The
NewClientPipedocs say it can be used to connect to an SFTP server over TCP/TLS, but the only example runs thesshcommand. This addsExampleNewClientPipe_tls(tls.Dialand pass the connection toNewClientPipe) andExampleNewServer_tls(tls.ListenandNewServeron each accepted connection).Since SFTP has no authentication of its own, both use client certificates (
RequireAndVerifyClientCerton the server), and the comments say that plain TCP has neither encryption nor authentication. The server example also points out thatNewServergives clients the local filesystem as the process's user, and suggestsNewRequestServerto restrict that.I ran the same code end to end with a throwaway CA: listing a directory over TLS works, and a client without a certificate is rejected during the handshake.
These are added at the end of
example_test.go, so they don't overlap with #688, which adds anotherNewClientPipeexample after the existing one.