Documentation ¶
Overview ¶
Package sftp handles file transfers client-side via SFTP.
Index ¶
Constants ¶
const ( // FileTransferDstPath is the dstPath (location) for the requested file transfer. This would be equal // to the file to be downloaded, or location for a file to be uploaded. FileTransferDstPath string = "TELEPORT_FILE_TRANSFER_DST_PATH" // FileTransferRequestID is an optional parameter id of an file transfer request that has gone through // an approval process during a moderated session to allow a file transfer scp command to be executed // used as a value in the file transfer context and env var for exec session FileTransferRequestID contextKey = "TELEPORT_FILE_TRANSFER_REQUEST_ID" // ModeratedSessionID is an optional parameter sent during SCP requests to specify which moderated session // to check for valid FileTransferRequests // used as a value in the file transfer context and env var for exec session ModeratedSessionID contextKey = "TELEPORT_MODERATED_SESSION_ID" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // ProgressStream is a callback to return a read/writer for printing the progress // (used only on the client) ProgressStream func(fileInfo os.FileInfo) io.ReadWriter // Log optionally specifies the logger Log log.FieldLogger // contains filtered or unexported fields }
Config describes the settings of a file transfer
func CreateDownloadConfig ¶
CreateDownloadConfig returns a Config ready to download files over SFTP.
func CreateHTTPDownloadConfig ¶
func CreateHTTPDownloadConfig(req HTTPTransferRequest) (*Config, error)
CreateHTTPDownloadConfig returns a Config ready to download a file from over SFTP and write it to a HTTP response.
func CreateHTTPUploadConfig ¶
func CreateHTTPUploadConfig(req HTTPTransferRequest) (*Config, error)
CreateHTTPUploadConfig returns a Config ready to upload a file from a HTTP request over SFTP.
func CreateUploadConfig ¶
CreateUploadConfig returns a Config ready to upload files over SFTP.
type Destination ¶
type Destination struct { // Login is an optional login username Login string // Host is a host to copy to/from Host *utils.NetAddr // Path is a path to copy to/from. // An empty path name is valid, and it refers to the user's default directory (usually // the user's home directory). // See https://tools.ietf.org/html/draft-ietf-secsh-filexfer-09#page-14, 'File Names' Path string }
Destination is a remote SFTP destination to copy to or from.
func ParseDestination ¶
func ParseDestination(input string) (*Destination, error)
ParseDestination takes a string representing a remote resource for SFTP to download/upload in the form "[user@]host:path" and parses it into a structured form.
See https://tools.ietf.org/html/draft-ietf-secsh-filexfer-09#page-14, 'File Names' section about details on file names.
type FileSystem ¶
type FileSystem interface { // Type returns whether the filesystem is "local" or "remote" Type() string // Glob returns matching files of a glob pattern Glob(ctx context.Context, pattern string) ([]string, error) // Stat returns info about a file Stat(ctx context.Context, path string) (os.FileInfo, error) // ReadDir returns information about files contained within a directory ReadDir(ctx context.Context, path string) ([]os.FileInfo, error) // Open opens a file Open(ctx context.Context, path string) (fs.File, error) // Create creates a new file Create(ctx context.Context, path string, size int64) (io.WriteCloser, error) // Mkdir creates a directory Mkdir(ctx context.Context, path string) error // Chmod sets file permissions Chmod(ctx context.Context, path string, mode os.FileMode) error // Chtimes sets file access and modification time Chtimes(ctx context.Context, path string, atime, mtime time.Time) error }
FileSystem describes file operations to be done either locally or over SFTP
type HTTPTransferRequest ¶
type HTTPTransferRequest struct { // Src is the source file name Src string // Dst is the destination file name Dst string // HTTPRequest is where the source file will be read from for // file upload transfers HTTPRequest *http.Request // HTTPResponse is where the destination file will be written to for // file download transfers HTTPResponse http.ResponseWriter }
HTTPTransferRequest describes file transfer request over HTTP.