github.com/pkg/sftp@v1.13.6/request-readme.md (about) 1 # Request Based SFTP API 2 3 The request based API allows for custom backends in a way similar to the http 4 package. In order to create a backend you need to implement 4 handler 5 interfaces; one for reading, one for writing, one for misc commands and one for 6 listing files. Each has 1 required method and in each case those methods take 7 the Request as the only parameter and they each return something different. 8 These 4 interfaces are enough to handle all the SFTP traffic in a simplified 9 manner. 10 11 The Request structure has 5 public fields which you will deal with. 12 13 - Method (string) - string name of incoming call 14 - Filepath (string) - POSIX path of file to act on 15 - Flags (uint32) - 32bit bitmask value of file open/create flags 16 - Attrs ([]byte) - byte string of file attribute data 17 - Target (string) - target path for renames and sym-links 18 19 Below are the methods and a brief description of what they need to do. 20 21 ### Fileread(*Request) (io.Reader, error) 22 23 Handler for "Get" method and returns an io.Reader for the file which the server 24 then sends to the client. 25 26 ### Filewrite(*Request) (io.Writer, error) 27 28 Handler for "Put" method and returns an io.Writer for the file which the server 29 then writes the uploaded file to. The file opening "pflags" are currently 30 preserved in the Request.Flags field as a 32bit bitmask value. See the [SFTP 31 spec](https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-6.3) for 32 details. 33 34 ### Filecmd(*Request) error 35 36 Handles "SetStat", "Rename", "Rmdir", "Mkdir" and "Symlink" methods. Makes the 37 appropriate changes and returns nil for success or an filesystem like error 38 (eg. os.ErrNotExist). The attributes are currently propagated in their raw form 39 ([]byte) and will need to be unmarshalled to be useful. See the respond method 40 on sshFxpSetstatPacket for example of you might want to do this. 41 42 ### Fileinfo(*Request) ([]os.FileInfo, error) 43 44 Handles "List", "Stat", "Readlink" methods. Gathers/creates FileInfo structs 45 with the data on the files and returns in a list (list of 1 for Stat and 46 Readlink). 47 48 49 ## TODO 50 51 - Add support for API users to see trace/debugging info of what is going on 52 inside SFTP server. 53 - Unmarshal the file attributes into a structure on the Request object.