Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a net/http-like API for the Server type #84

Closed
6 tasks
mdlayher opened this issue Jan 15, 2016 · 4 comments
Closed
6 tasks

Provide a net/http-like API for the Server type #84

mdlayher opened this issue Jan 15, 2016 · 4 comments

Comments

@mdlayher
Copy link
Member

This will be an issue to track progress for providing a net/http-like API for the Server type.

TODO list:

  • create sftp.Handler interface
  • create sftp.Request type with request information
  • create sftp.Responder interface to respond to clients
  • create sftp.FileServer type which can serve files from the local filesystem, as is done now.
    • enables generic interface backend for fronting many different "filesystems" with SFTP
    • could also implement chroot-like functionality this way
  • figure out how to cleanly integrate underlying SSH server configuration
    • retrieve information like SSH username

Ideas:

Here's a couple sketches of what this might look like from previous samples:

type Handler struct {}

func (h *Handler) ServeSFTP(w sftp.Responder, r *sftp.Request) {
    log.Println("request:", r.Type)
    _, _ = sftp.PermissionDenied(w)
}

func main() {
    s := &sftp.Server{
        Handler: &Handler{},
    }

    _ = s.Serve()
}
func ServeSFTP(w sftp.Responder, r *sftp.Request) {
    if !authenticated(r) {
        sftp.FileServer(sftp.Dir("/srv/sftpchroot/"))(w, r)
        return
    }

    sftp.FileServer(sftp.Dir("/"))(w, r)
}

cc: @davecheney @marksheahan @xor-gate @punkeel

@punkeel
Copy link

punkeel commented Jan 17, 2016

I don't understand how this would work. (http is stateless, SFTP is not. I think there should be a shared "session" object, at least ... But I don't see how to name it/what it could hold)

@eikenb
Copy link
Member

eikenb commented May 6, 2016

@punkeel - The SFTP server implements version 3 of the spec which allows for stateless servers (other versions may as well). For how this works read the intro to section 6 in the RFC.

https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#section-6

davecheney added a commit that referenced this issue Jun 15, 2016
davecheney added a commit that referenced this issue Jun 15, 2016
* Centralise packet handling for common packets

Updates #84, #95, #96

* use sendError
techjacker pushed a commit to techjacker/sftp that referenced this issue Dec 5, 2016
* Centralise packet handling for common packets

Updates pkg#84, pkg#95, pkg#96

* use sendError
@eikenb
Copy link
Member

eikenb commented Jan 14, 2017

#130 isn't exactly this, but I think it covers some of the same ground. What do you think?

@eikenb
Copy link
Member

eikenb commented May 22, 2017

I'm going to say this is done enough as #130 addresses most of it and what it doesn't aren't as useful in the context of SFTP.

@eikenb eikenb closed this as completed May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants