sftp

package module
v0.0.0-...-a015971 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2022 License: BSD-2-Clause Imports: 30 Imported by: 0

README

sftp

The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem.

This is a fork of github.com/pkg/sftp that changes the server to allow for a plugable backend and adds an S3 and file system backend. The file system backend is mostly used for tests and is similar to the previous behavior. Additionally, this adds a ManagedServer component that can be used to easily create a server with an arbitrary backend.

Tests that depend on the details of the file system server (mostly client tests) are being skipped.

usage and examples

See godoc.org/github.com/pkg/sftp for examples and usage.

The basic operation of the package mirrors the facilities of the os package.

The Walker interface for directory traversal is heavily inspired by Keith Rarick's fs package.

roadmap

  • There is way too much duplication in the Client methods. If there was an unmarshal(interface{}) method this would reduce a heap of the duplication.

contributing

We welcome pull requests, bug fixes and issue reports.

Before proposing a large change, first please discuss your change by raising an issue.

Documentation

Overview

Package sftp implements the SSH File Transfer Protocol as described in https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt

Example
package main

import (
	"log"

	"github.com/Clever/sftp"
	"golang.org/x/crypto/ssh"
)

func main() {
	var conn *ssh.Client

	// open an SFTP session over an existing ssh connection.
	sftp, err := sftp.NewClient(conn)
	if err != nil {
		log.Fatal(err)
	}
	defer sftp.Close()

	// walk a directory
	w := sftp.Walk("/home/user")
	for w.Step() {
		if w.Err() != nil {
			continue
		}
		log.Println(w.Path())
	}

	// leave your mark
	f, err := sftp.Create("hello.txt")
	if err != nil {
		log.Fatal(err)
	}
	if _, err := f.Write([]byte("Hello world!")); err != nil {
		log.Fatal(err)
	}

	// check it's there
	fi, err := sftp.Lstat("hello.txt")
	if err != nil {
		log.Fatal(err)
	}
	log.Println(fi)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var BLOCK_DOWNLOADS_IP_ADDRESSES []string
View Source
var (

	// ErrInvalidUpstream returned if connection fails or is not accepted
	ErrInvalidUpstream = errors.New("upstream connection address not trusted for PROXY information")
)

Functions

func MaxPacket

func MaxPacket(size int) func(*Client) error

MaxPacket sets the maximum size of the payload.

func TranslatePath

func TranslatePath(prefix, home, path string) (string, error)

translatePath takes in a S3 root prefix, a home directory, and either an absolute or relative path to append, and returns a cleaned and validated path. It will resolve things like '..' while disallowing the prefix to be escaped. It also preserves a single trailing slash if one is present, so it can be used on both directories and files.

Types

type Alerter

type Alerter func(title string, metadata map[string]interface{})

Alerter is the function signature for an optional alerting function to be called in error cases.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an SFTP session on a *ssh.ClientConn SSH connection. Multiple Clients can be active on a single SSH connection, and a Client may be called concurrently from multiple Goroutines.

Client implements the github.com/kr/fs.FileSystem interface.

func NewClient

func NewClient(conn *ssh.Client, opts ...func(*Client) error) (*Client, error)

NewClient creates a new SFTP client on conn, using zero or more option functions.

func NewClientPipe

func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...func(*Client) error) (*Client, error)

NewClientPipe creates a new SFTP client given a Reader and a WriteCloser. This can be used for connecting to an SFTP server over TCP/TLS or by using the system's ssh client program (e.g. via exec.Command).

Example
package main

import (
	"fmt"
	"log"
	"os"
	"os/exec"

	"github.com/Clever/sftp"
)

func main() {
	// Connect to a remote host and request the sftp subsystem via the 'ssh'
	// command.  This assumes that passwordless login is correctly configured.
	cmd := exec.Command("ssh", "example.com", "-s", "sftp")

	// send errors from ssh to stderr
	cmd.Stderr = os.Stderr

	// get stdin and stdout
	wr, err := cmd.StdinPipe()
	if err != nil {
		log.Fatal(err)
	}
	rd, err := cmd.StdoutPipe()
	if err != nil {
		log.Fatal(err)
	}

	// start the process
	if err := cmd.Start(); err != nil {
		log.Fatal(err)
	}
	defer cmd.Wait()

	// open the SFTP session
	client, err := sftp.NewClientPipe(rd, wr)
	if err != nil {
		log.Fatal(err)
	}

	// read a directory
	list, err := client.ReadDir("/")
	if err != nil {
		log.Fatal(err)
	}

	// print contents
	for _, item := range list {
		fmt.Println(item.Name())
	}

	// close the connection
	client.Close()
}
Output:

func (*Client) Chmod

func (c *Client) Chmod(path string, mode os.FileMode) error

Chmod changes the permissions of the named file.

func (*Client) Chown

func (c *Client) Chown(path string, uid, gid int) error

Chown changes the user and group owners of the named file.

func (*Client) Chtimes

func (c *Client) Chtimes(path string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file.

func (*Client) Close

func (c *Client) Close() error

Close closes the SFTP session.

func (*Client) Create

func (c *Client) Create(path string) (*File, error)

Create creates the named file mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.

func (*Client) Getwd

func (c *Client) Getwd() (string, error)

Getwd returns the current working directory of the server. Operations involving relative paths will be based at this location.

func (*Client) Join

func (c *Client) Join(elem ...string) string

Join joins any number of path elements into a single path, adding a separating slash if necessary. The result is Cleaned; in particular, all empty strings are ignored.

func (*Client) Lstat

func (c *Client) Lstat(p string) (os.FileInfo, error)

Lstat returns a FileInfo structure describing the file specified by path 'p'. If 'p' is a symbolic link, the returned FileInfo structure describes the symbolic link.

func (*Client) Mkdir

func (c *Client) Mkdir(path string) error

Mkdir creates the specified directory. An error will be returned if a file or directory with the specified path already exists, or if the directory's parent folder does not exist (the method cannot create complete paths).

func (*Client) Open

func (c *Client) Open(path string) (*File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.

func (*Client) OpenFile

func (c *Client) OpenFile(path string, f int) (*File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.). If successful, methods on the returned File can be used for I/O.

func (*Client) ReadDir

func (c *Client) ReadDir(p string) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of directory entries.

func (c *Client) ReadLink(p string) (string, error)

ReadLink reads the target of a symbolic link.

func (*Client) Remove

func (c *Client) Remove(path string) error

Remove removes the specified file or directory. An error will be returned if no file or directory with the specified path exists, or if the specified directory is not empty.

func (*Client) Rename

func (c *Client) Rename(oldname, newname string) error

Rename renames a file.

func (*Client) Stat

func (c *Client) Stat(p string) (os.FileInfo, error)

Stat returns a FileInfo structure describing the file specified by path 'p'. If 'p' is a symbolic link, the returned FileInfo structure describes the referent file.

func (*Client) StatVFS

func (c *Client) StatVFS(path string) (*StatVFS, error)

StatVFS retrieves VFS statistics from a remote host.

It implements the statvfs@openssh.com SSH_FXP_EXTENDED feature from http://www.opensource.apple.com/source/OpenSSH/OpenSSH-175/openssh/PROTOCOL?txt.

func (c *Client) Symlink(oldname, newname string) error

Symlink creates a symbolic link at 'newname', pointing at target 'oldname'

func (*Client) Truncate

func (c *Client) Truncate(path string, size int64) error

Truncate sets the size of the named file. Although it may be safely assumed that if the size is less than its current size it will be truncated to fit, the SFTP protocol does not specify what behavior the server should do when setting size greater than the current size.

func (*Client) Walk

func (c *Client) Walk(root string) *fs.Walker

Walk returns a new Walker rooted at root.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is used to wrap and underlying connection which may be speaking the Proxy Protocol. If it is, the RemoteAddr() will return the address of the client instead of the proxy address.

func NewConn

func NewConn(conn net.Conn, timeout time.Duration) *Conn

NewConn is used to wrap a net.Conn that may be speaking the proxy protocol into a proxyproto.Conn

func (*Conn) Close

func (p *Conn) Close() error

Close closes the connection

func (*Conn) LocalAddr

func (p *Conn) LocalAddr() net.Addr

LocalAddr returns the address of the client

func (*Conn) Read

func (p *Conn) Read(b []byte) (int, error)

Read is check for the proxy protocol header when doing the initial scan. If there is an error parsing the header, it is returned and the socket is closed.

func (*Conn) RemoteAddr

func (p *Conn) RemoteAddr() net.Addr

RemoteAddr returns the address of the client if the proxy protocol is being used, otherwise just returns the address of the socket peer. If there is an error parsing the header, the address of the client is not returned, and the socket is closed. Once implication of this is that the call could block if the client is slow. Using a Deadline is recommended if this is called before Read()

func (*Conn) SetDeadline

func (p *Conn) SetDeadline(t time.Time) error

SetDeadline sets a timeout

func (*Conn) SetReadDeadline

func (p *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets a timeout for reads

func (*Conn) SetWriteDeadline

func (p *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets a timeout for writes

func (*Conn) Write

func (p *Conn) Write(b []byte) (int, error)

type DriverGenerator

type DriverGenerator func(LoginRequest) ServerDriver

DriverGenerator is a function that creates an SFTP ServerDriver if the login request is valid.

type File

type File struct {
	// contains filtered or unexported fields
}

File represents a remote file.

func (*File) Chmod

func (f *File) Chmod(mode os.FileMode) error

Chmod changes the permissions of the current file.

func (*File) Chown

func (f *File) Chown(uid, gid int) error

Chown changes the uid/gid of the current file.

func (*File) Close

func (f *File) Close() error

Close closes the File, rendering it unusable for I/O. It returns an error, if any.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file as presented to Open or Create.

func (*File) Read

func (f *File) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF.

func (*File) ReadFrom

func (f *File) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads data from r until EOF and writes it to the file. The return value is the number of bytes read. Any error except io.EOF encountered during the read is also returned.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker by setting the client offset for the next Read or Write. It returns the next offset read. Seeking before or after the end of the file is undefined. Seeking relative to the end calls Stat.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns the FileInfo structure describing file. If there is an error.

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate sets the size of the current file. Although it may be safely assumed that if the size is less than its current size it will be truncated to fit, the SFTP protocol does not specify what behavior the server should do when setting size greater than the current size.

func (*File) Write

func (f *File) Write(b []byte) (int, error)

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (int64, error)

WriteTo writes the file to w. The return value is the number of bytes written. Any error encountered during the write is also returned.

type FileStat

type FileStat struct {
	Size     uint64
	Mode     uint32
	Mtime    uint32
	Atime    uint32
	UID      uint32
	GID      uint32
	Extended []StatExtended
}

FileStat holds the original unmarshalled values from a call to READDIR or *STAT. It is exported for the purposes of accessing the raw values via os.FileInfo.Sys()

type Listener

type Listener struct {
	Listener           net.Listener
	ProxyHeaderTimeout time.Duration
	SourceCheck        SourceChecker
}

Listener is used to wrap an underlying listener, whose connections may be using the HAProxy Proxy Protocol (version 1). If the connection is using the protocol, the RemoteAddr() will return the correct client address.

Optionally define ProxyHeaderTimeout to set a maximum time to receive the Proxy Protocol Header. Zero means no timeout.

func (*Listener) Accept

func (p *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (p *Listener) Addr() net.Addr

Addr returns the underlying listener's network address.

func (*Listener) Close

func (p *Listener) Close() error

Close closes the underlying listener.

type Logger

type Logger interface {
	InfoD(title string, meta map[string]interface{})
	ErrorD(title string, meta map[string]interface{})
}

Logger is an abstraction for how logging will be performed by the server. It matches a subset of the Clever/kayvee-go library.

type LoginRequest

type LoginRequest struct {
	Username   string
	Password   string
	PublicKey  string
	RemoteAddr net.Addr
}

LoginRequest is the metadata associated with a login request that is passed to the driverGenerator function in order for it to approve/deny the request.

type ManagedServer

type ManagedServer struct {
	// contains filtered or unexported fields
}

ManagedServer is our term for the SFTP server.

func NewManagedServer

func NewManagedServer(driverGenerator DriverGenerator, lg Logger, alertFn Alerter) *ManagedServer

NewManagedServer creates a new ManagedServer which conditionally serves requests based on the output of driverGenerator.

func (ManagedServer) Start

func (m ManagedServer) Start(port int, rawPrivateKeys [][]byte, ciphers, macs []string)

Start actually starts the server and begins fielding requests.

type MockS3API

type MockS3API struct {
	// contains filtered or unexported fields
}

Mock of S3API interface

func NewMockS3API

func NewMockS3API(ctrl *gomock.Controller) *MockS3API

func (*MockS3API) AbortMultipartUpload

func (_m *MockS3API) AbortMultipartUpload(_param0 *s3.AbortMultipartUploadInput) (*s3.AbortMultipartUploadOutput, error)

func (*MockS3API) AbortMultipartUploadRequest

func (_m *MockS3API) AbortMultipartUploadRequest(_param0 *s3.AbortMultipartUploadInput) (*request.Request, *s3.AbortMultipartUploadOutput)

func (*MockS3API) CompleteMultipartUpload

func (_m *MockS3API) CompleteMultipartUpload(_param0 *s3.CompleteMultipartUploadInput) (*s3.CompleteMultipartUploadOutput, error)

func (*MockS3API) CompleteMultipartUploadRequest

func (_m *MockS3API) CompleteMultipartUploadRequest(_param0 *s3.CompleteMultipartUploadInput) (*request.Request, *s3.CompleteMultipartUploadOutput)

func (*MockS3API) CopyObject

func (_m *MockS3API) CopyObject(_param0 *s3.CopyObjectInput) (*s3.CopyObjectOutput, error)

func (*MockS3API) CopyObjectRequest

func (_m *MockS3API) CopyObjectRequest(_param0 *s3.CopyObjectInput) (*request.Request, *s3.CopyObjectOutput)

func (*MockS3API) CreateBucket

func (_m *MockS3API) CreateBucket(_param0 *s3.CreateBucketInput) (*s3.CreateBucketOutput, error)

func (*MockS3API) CreateBucketRequest

func (_m *MockS3API) CreateBucketRequest(_param0 *s3.CreateBucketInput) (*request.Request, *s3.CreateBucketOutput)

func (*MockS3API) CreateMultipartUpload

func (_m *MockS3API) CreateMultipartUpload(_param0 *s3.CreateMultipartUploadInput) (*s3.CreateMultipartUploadOutput, error)

func (*MockS3API) CreateMultipartUploadRequest

func (_m *MockS3API) CreateMultipartUploadRequest(_param0 *s3.CreateMultipartUploadInput) (*request.Request, *s3.CreateMultipartUploadOutput)

func (*MockS3API) DeleteBucket

func (_m *MockS3API) DeleteBucket(_param0 *s3.DeleteBucketInput) (*s3.DeleteBucketOutput, error)

func (*MockS3API) DeleteBucketCors

func (_m *MockS3API) DeleteBucketCors(_param0 *s3.DeleteBucketCorsInput) (*s3.DeleteBucketCorsOutput, error)

func (*MockS3API) DeleteBucketCorsRequest

func (_m *MockS3API) DeleteBucketCorsRequest(_param0 *s3.DeleteBucketCorsInput) (*request.Request, *s3.DeleteBucketCorsOutput)

func (*MockS3API) DeleteBucketLifecycle

func (_m *MockS3API) DeleteBucketLifecycle(_param0 *s3.DeleteBucketLifecycleInput) (*s3.DeleteBucketLifecycleOutput, error)

func (*MockS3API) DeleteBucketLifecycleRequest

func (_m *MockS3API) DeleteBucketLifecycleRequest(_param0 *s3.DeleteBucketLifecycleInput) (*request.Request, *s3.DeleteBucketLifecycleOutput)

func (*MockS3API) DeleteBucketPolicy

func (_m *MockS3API) DeleteBucketPolicy(_param0 *s3.DeleteBucketPolicyInput) (*s3.DeleteBucketPolicyOutput, error)

func (*MockS3API) DeleteBucketPolicyRequest

func (_m *MockS3API) DeleteBucketPolicyRequest(_param0 *s3.DeleteBucketPolicyInput) (*request.Request, *s3.DeleteBucketPolicyOutput)

func (*MockS3API) DeleteBucketReplication

func (_m *MockS3API) DeleteBucketReplication(_param0 *s3.DeleteBucketReplicationInput) (*s3.DeleteBucketReplicationOutput, error)

func (*MockS3API) DeleteBucketReplicationRequest

func (_m *MockS3API) DeleteBucketReplicationRequest(_param0 *s3.DeleteBucketReplicationInput) (*request.Request, *s3.DeleteBucketReplicationOutput)

func (*MockS3API) DeleteBucketRequest

func (_m *MockS3API) DeleteBucketRequest(_param0 *s3.DeleteBucketInput) (*request.Request, *s3.DeleteBucketOutput)

func (*MockS3API) DeleteBucketTagging

func (_m *MockS3API) DeleteBucketTagging(_param0 *s3.DeleteBucketTaggingInput) (*s3.DeleteBucketTaggingOutput, error)

func (*MockS3API) DeleteBucketTaggingRequest

func (_m *MockS3API) DeleteBucketTaggingRequest(_param0 *s3.DeleteBucketTaggingInput) (*request.Request, *s3.DeleteBucketTaggingOutput)

func (*MockS3API) DeleteBucketWebsite

func (_m *MockS3API) DeleteBucketWebsite(_param0 *s3.DeleteBucketWebsiteInput) (*s3.DeleteBucketWebsiteOutput, error)

func (*MockS3API) DeleteBucketWebsiteRequest

func (_m *MockS3API) DeleteBucketWebsiteRequest(_param0 *s3.DeleteBucketWebsiteInput) (*request.Request, *s3.DeleteBucketWebsiteOutput)

func (*MockS3API) DeleteObject

func (_m *MockS3API) DeleteObject(_param0 *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error)

func (*MockS3API) DeleteObjectRequest

func (_m *MockS3API) DeleteObjectRequest(_param0 *s3.DeleteObjectInput) (*request.Request, *s3.DeleteObjectOutput)

func (*MockS3API) DeleteObjects

func (_m *MockS3API) DeleteObjects(_param0 *s3.DeleteObjectsInput) (*s3.DeleteObjectsOutput, error)

func (*MockS3API) DeleteObjectsRequest

func (_m *MockS3API) DeleteObjectsRequest(_param0 *s3.DeleteObjectsInput) (*request.Request, *s3.DeleteObjectsOutput)

func (*MockS3API) EXPECT

func (_m *MockS3API) EXPECT() *_MockS3APIRecorder

func (*MockS3API) GetBucketAccelerateConfiguration

func (_m *MockS3API) GetBucketAccelerateConfiguration(_param0 *s3.GetBucketAccelerateConfigurationInput) (*s3.GetBucketAccelerateConfigurationOutput, error)

func (*MockS3API) GetBucketAcl

func (_m *MockS3API) GetBucketAcl(_param0 *s3.GetBucketAclInput) (*s3.GetBucketAclOutput, error)

func (*MockS3API) GetBucketAclRequest

func (_m *MockS3API) GetBucketAclRequest(_param0 *s3.GetBucketAclInput) (*request.Request, *s3.GetBucketAclOutput)

func (*MockS3API) GetBucketCors

func (_m *MockS3API) GetBucketCors(_param0 *s3.GetBucketCorsInput) (*s3.GetBucketCorsOutput, error)

func (*MockS3API) GetBucketCorsRequest

func (_m *MockS3API) GetBucketCorsRequest(_param0 *s3.GetBucketCorsInput) (*request.Request, *s3.GetBucketCorsOutput)

func (*MockS3API) GetBucketLifecycle

func (_m *MockS3API) GetBucketLifecycle(_param0 *s3.GetBucketLifecycleInput) (*s3.GetBucketLifecycleOutput, error)

func (*MockS3API) GetBucketLifecycleConfiguration

func (_m *MockS3API) GetBucketLifecycleConfiguration(_param0 *s3.GetBucketLifecycleConfigurationInput) (*s3.GetBucketLifecycleConfigurationOutput, error)

func (*MockS3API) GetBucketLifecycleRequest

func (_m *MockS3API) GetBucketLifecycleRequest(_param0 *s3.GetBucketLifecycleInput) (*request.Request, *s3.GetBucketLifecycleOutput)

func (*MockS3API) GetBucketLocation

func (_m *MockS3API) GetBucketLocation(_param0 *s3.GetBucketLocationInput) (*s3.GetBucketLocationOutput, error)

func (*MockS3API) GetBucketLocationRequest

func (_m *MockS3API) GetBucketLocationRequest(_param0 *s3.GetBucketLocationInput) (*request.Request, *s3.GetBucketLocationOutput)

func (*MockS3API) GetBucketLogging

func (_m *MockS3API) GetBucketLogging(_param0 *s3.GetBucketLoggingInput) (*s3.GetBucketLoggingOutput, error)

func (*MockS3API) GetBucketLoggingRequest

func (_m *MockS3API) GetBucketLoggingRequest(_param0 *s3.GetBucketLoggingInput) (*request.Request, *s3.GetBucketLoggingOutput)

func (*MockS3API) GetBucketNotificationConfiguration

func (_m *MockS3API) GetBucketNotificationConfiguration(_param0 *s3.GetBucketNotificationConfigurationRequest) (*s3.NotificationConfiguration, error)

func (*MockS3API) GetBucketNotificationConfigurationRequest

func (_m *MockS3API) GetBucketNotificationConfigurationRequest(_param0 *s3.GetBucketNotificationConfigurationRequest) (*request.Request, *s3.NotificationConfiguration)

func (*MockS3API) GetBucketPolicy

func (_m *MockS3API) GetBucketPolicy(_param0 *s3.GetBucketPolicyInput) (*s3.GetBucketPolicyOutput, error)

func (*MockS3API) GetBucketPolicyRequest

func (_m *MockS3API) GetBucketPolicyRequest(_param0 *s3.GetBucketPolicyInput) (*request.Request, *s3.GetBucketPolicyOutput)

func (*MockS3API) GetBucketReplication

func (_m *MockS3API) GetBucketReplication(_param0 *s3.GetBucketReplicationInput) (*s3.GetBucketReplicationOutput, error)

func (*MockS3API) GetBucketReplicationRequest

func (_m *MockS3API) GetBucketReplicationRequest(_param0 *s3.GetBucketReplicationInput) (*request.Request, *s3.GetBucketReplicationOutput)

func (*MockS3API) GetBucketRequestPayment

func (_m *MockS3API) GetBucketRequestPayment(_param0 *s3.GetBucketRequestPaymentInput) (*s3.GetBucketRequestPaymentOutput, error)

func (*MockS3API) GetBucketRequestPaymentRequest

func (_m *MockS3API) GetBucketRequestPaymentRequest(_param0 *s3.GetBucketRequestPaymentInput) (*request.Request, *s3.GetBucketRequestPaymentOutput)

func (*MockS3API) GetBucketTagging

func (_m *MockS3API) GetBucketTagging(_param0 *s3.GetBucketTaggingInput) (*s3.GetBucketTaggingOutput, error)

func (*MockS3API) GetBucketTaggingRequest

func (_m *MockS3API) GetBucketTaggingRequest(_param0 *s3.GetBucketTaggingInput) (*request.Request, *s3.GetBucketTaggingOutput)

func (*MockS3API) GetBucketVersioning

func (_m *MockS3API) GetBucketVersioning(_param0 *s3.GetBucketVersioningInput) (*s3.GetBucketVersioningOutput, error)

func (*MockS3API) GetBucketVersioningRequest

func (_m *MockS3API) GetBucketVersioningRequest(_param0 *s3.GetBucketVersioningInput) (*request.Request, *s3.GetBucketVersioningOutput)

func (*MockS3API) GetBucketWebsite

func (_m *MockS3API) GetBucketWebsite(_param0 *s3.GetBucketWebsiteInput) (*s3.GetBucketWebsiteOutput, error)

func (*MockS3API) GetBucketWebsiteRequest

func (_m *MockS3API) GetBucketWebsiteRequest(_param0 *s3.GetBucketWebsiteInput) (*request.Request, *s3.GetBucketWebsiteOutput)

func (*MockS3API) GetObject

func (_m *MockS3API) GetObject(_param0 *s3.GetObjectInput) (*s3.GetObjectOutput, error)

func (*MockS3API) GetObjectAcl

func (_m *MockS3API) GetObjectAcl(_param0 *s3.GetObjectAclInput) (*s3.GetObjectAclOutput, error)

func (*MockS3API) GetObjectAclRequest

func (_m *MockS3API) GetObjectAclRequest(_param0 *s3.GetObjectAclInput) (*request.Request, *s3.GetObjectAclOutput)

func (*MockS3API) GetObjectRequest

func (_m *MockS3API) GetObjectRequest(_param0 *s3.GetObjectInput) (*request.Request, *s3.GetObjectOutput)

func (*MockS3API) GetObjectTorrent

func (_m *MockS3API) GetObjectTorrent(_param0 *s3.GetObjectTorrentInput) (*s3.GetObjectTorrentOutput, error)

func (*MockS3API) GetObjectTorrentRequest

func (_m *MockS3API) GetObjectTorrentRequest(_param0 *s3.GetObjectTorrentInput) (*request.Request, *s3.GetObjectTorrentOutput)

func (*MockS3API) HeadBucket

func (_m *MockS3API) HeadBucket(_param0 *s3.HeadBucketInput) (*s3.HeadBucketOutput, error)

func (*MockS3API) HeadBucketRequest

func (_m *MockS3API) HeadBucketRequest(_param0 *s3.HeadBucketInput) (*request.Request, *s3.HeadBucketOutput)

func (*MockS3API) HeadObject

func (_m *MockS3API) HeadObject(_param0 *s3.HeadObjectInput) (*s3.HeadObjectOutput, error)

func (*MockS3API) HeadObjectRequest

func (_m *MockS3API) HeadObjectRequest(_param0 *s3.HeadObjectInput) (*request.Request, *s3.HeadObjectOutput)

func (*MockS3API) ListBuckets

func (_m *MockS3API) ListBuckets(_param0 *s3.ListBucketsInput) (*s3.ListBucketsOutput, error)

func (*MockS3API) ListBucketsRequest

func (_m *MockS3API) ListBucketsRequest(_param0 *s3.ListBucketsInput) (*request.Request, *s3.ListBucketsOutput)

func (*MockS3API) ListMultipartUploads

func (_m *MockS3API) ListMultipartUploads(_param0 *s3.ListMultipartUploadsInput) (*s3.ListMultipartUploadsOutput, error)

func (*MockS3API) ListMultipartUploadsPages

func (_m *MockS3API) ListMultipartUploadsPages(_param0 *s3.ListMultipartUploadsInput, _param1 func(*s3.ListMultipartUploadsOutput, bool) bool) error

func (*MockS3API) ListMultipartUploadsRequest

func (_m *MockS3API) ListMultipartUploadsRequest(_param0 *s3.ListMultipartUploadsInput) (*request.Request, *s3.ListMultipartUploadsOutput)

func (*MockS3API) ListObjectVersions

func (_m *MockS3API) ListObjectVersions(_param0 *s3.ListObjectVersionsInput) (*s3.ListObjectVersionsOutput, error)

func (*MockS3API) ListObjectVersionsPages

func (_m *MockS3API) ListObjectVersionsPages(_param0 *s3.ListObjectVersionsInput, _param1 func(*s3.ListObjectVersionsOutput, bool) bool) error

func (*MockS3API) ListObjectVersionsRequest

func (_m *MockS3API) ListObjectVersionsRequest(_param0 *s3.ListObjectVersionsInput) (*request.Request, *s3.ListObjectVersionsOutput)

func (*MockS3API) ListObjects

func (_m *MockS3API) ListObjects(_param0 *s3.ListObjectsInput) (*s3.ListObjectsOutput, error)

func (*MockS3API) ListObjectsPages

func (_m *MockS3API) ListObjectsPages(_param0 *s3.ListObjectsInput, _param1 func(*s3.ListObjectsOutput, bool) bool) error

func (*MockS3API) ListObjectsRequest

func (_m *MockS3API) ListObjectsRequest(_param0 *s3.ListObjectsInput) (*request.Request, *s3.ListObjectsOutput)

func (*MockS3API) ListObjectsV2

func (_m *MockS3API) ListObjectsV2(_param0 *s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error)

func (*MockS3API) ListObjectsV2Request

func (_m *MockS3API) ListObjectsV2Request(_param0 *s3.ListObjectsV2Input) (*request.Request, *s3.ListObjectsV2Output)

func (*MockS3API) ListParts

func (_m *MockS3API) ListParts(_param0 *s3.ListPartsInput) (*s3.ListPartsOutput, error)

func (*MockS3API) ListPartsPages

func (_m *MockS3API) ListPartsPages(_param0 *s3.ListPartsInput, _param1 func(*s3.ListPartsOutput, bool) bool) error

func (*MockS3API) ListPartsRequest

func (_m *MockS3API) ListPartsRequest(_param0 *s3.ListPartsInput) (*request.Request, *s3.ListPartsOutput)

func (*MockS3API) PutBucketAccelerateConfiguration

func (_m *MockS3API) PutBucketAccelerateConfiguration(_param0 *s3.PutBucketAccelerateConfigurationInput) (*s3.PutBucketAccelerateConfigurationOutput, error)

func (*MockS3API) PutBucketAcl

func (_m *MockS3API) PutBucketAcl(_param0 *s3.PutBucketAclInput) (*s3.PutBucketAclOutput, error)

func (*MockS3API) PutBucketAclRequest

func (_m *MockS3API) PutBucketAclRequest(_param0 *s3.PutBucketAclInput) (*request.Request, *s3.PutBucketAclOutput)

func (*MockS3API) PutBucketCors

func (_m *MockS3API) PutBucketCors(_param0 *s3.PutBucketCorsInput) (*s3.PutBucketCorsOutput, error)

func (*MockS3API) PutBucketCorsRequest

func (_m *MockS3API) PutBucketCorsRequest(_param0 *s3.PutBucketCorsInput) (*request.Request, *s3.PutBucketCorsOutput)

func (*MockS3API) PutBucketLifecycle

func (_m *MockS3API) PutBucketLifecycle(_param0 *s3.PutBucketLifecycleInput) (*s3.PutBucketLifecycleOutput, error)

func (*MockS3API) PutBucketLifecycleConfiguration

func (_m *MockS3API) PutBucketLifecycleConfiguration(_param0 *s3.PutBucketLifecycleConfigurationInput) (*s3.PutBucketLifecycleConfigurationOutput, error)

func (*MockS3API) PutBucketLifecycleRequest

func (_m *MockS3API) PutBucketLifecycleRequest(_param0 *s3.PutBucketLifecycleInput) (*request.Request, *s3.PutBucketLifecycleOutput)

func (*MockS3API) PutBucketLogging

func (_m *MockS3API) PutBucketLogging(_param0 *s3.PutBucketLoggingInput) (*s3.PutBucketLoggingOutput, error)

func (*MockS3API) PutBucketLoggingRequest

func (_m *MockS3API) PutBucketLoggingRequest(_param0 *s3.PutBucketLoggingInput) (*request.Request, *s3.PutBucketLoggingOutput)

func (*MockS3API) PutBucketNotification

func (_m *MockS3API) PutBucketNotification(_param0 *s3.PutBucketNotificationInput) (*s3.PutBucketNotificationOutput, error)

func (*MockS3API) PutBucketNotificationRequest

func (_m *MockS3API) PutBucketNotificationRequest(_param0 *s3.PutBucketNotificationInput) (*request.Request, *s3.PutBucketNotificationOutput)

func (*MockS3API) PutBucketPolicy

func (_m *MockS3API) PutBucketPolicy(_param0 *s3.PutBucketPolicyInput) (*s3.PutBucketPolicyOutput, error)

func (*MockS3API) PutBucketPolicyRequest

func (_m *MockS3API) PutBucketPolicyRequest(_param0 *s3.PutBucketPolicyInput) (*request.Request, *s3.PutBucketPolicyOutput)

func (*MockS3API) PutBucketReplication

func (_m *MockS3API) PutBucketReplication(_param0 *s3.PutBucketReplicationInput) (*s3.PutBucketReplicationOutput, error)

func (*MockS3API) PutBucketReplicationRequest

func (_m *MockS3API) PutBucketReplicationRequest(_param0 *s3.PutBucketReplicationInput) (*request.Request, *s3.PutBucketReplicationOutput)

func (*MockS3API) PutBucketRequestPayment

func (_m *MockS3API) PutBucketRequestPayment(_param0 *s3.PutBucketRequestPaymentInput) (*s3.PutBucketRequestPaymentOutput, error)

func (*MockS3API) PutBucketRequestPaymentRequest

func (_m *MockS3API) PutBucketRequestPaymentRequest(_param0 *s3.PutBucketRequestPaymentInput) (*request.Request, *s3.PutBucketRequestPaymentOutput)

func (*MockS3API) PutBucketTagging

func (_m *MockS3API) PutBucketTagging(_param0 *s3.PutBucketTaggingInput) (*s3.PutBucketTaggingOutput, error)

func (*MockS3API) PutBucketTaggingRequest

func (_m *MockS3API) PutBucketTaggingRequest(_param0 *s3.PutBucketTaggingInput) (*request.Request, *s3.PutBucketTaggingOutput)

func (*MockS3API) PutBucketVersioning

func (_m *MockS3API) PutBucketVersioning(_param0 *s3.PutBucketVersioningInput) (*s3.PutBucketVersioningOutput, error)

func (*MockS3API) PutBucketVersioningRequest

func (_m *MockS3API) PutBucketVersioningRequest(_param0 *s3.PutBucketVersioningInput) (*request.Request, *s3.PutBucketVersioningOutput)

func (*MockS3API) PutBucketWebsite

func (_m *MockS3API) PutBucketWebsite(_param0 *s3.PutBucketWebsiteInput) (*s3.PutBucketWebsiteOutput, error)

func (*MockS3API) PutBucketWebsiteRequest

func (_m *MockS3API) PutBucketWebsiteRequest(_param0 *s3.PutBucketWebsiteInput) (*request.Request, *s3.PutBucketWebsiteOutput)

func (*MockS3API) PutObject

func (_m *MockS3API) PutObject(_param0 *s3.PutObjectInput) (*s3.PutObjectOutput, error)

func (*MockS3API) PutObjectAcl

func (_m *MockS3API) PutObjectAcl(_param0 *s3.PutObjectAclInput) (*s3.PutObjectAclOutput, error)

func (*MockS3API) PutObjectAclRequest

func (_m *MockS3API) PutObjectAclRequest(_param0 *s3.PutObjectAclInput) (*request.Request, *s3.PutObjectAclOutput)

func (*MockS3API) PutObjectRequest

func (_m *MockS3API) PutObjectRequest(_param0 *s3.PutObjectInput) (*request.Request, *s3.PutObjectOutput)

func (*MockS3API) RestoreObject

func (_m *MockS3API) RestoreObject(_param0 *s3.RestoreObjectInput) (*s3.RestoreObjectOutput, error)

func (*MockS3API) RestoreObjectRequest

func (_m *MockS3API) RestoreObjectRequest(_param0 *s3.RestoreObjectInput) (*request.Request, *s3.RestoreObjectOutput)

func (*MockS3API) UploadPart

func (_m *MockS3API) UploadPart(_param0 *s3.UploadPartInput) (*s3.UploadPartOutput, error)

func (*MockS3API) UploadPartCopy

func (_m *MockS3API) UploadPartCopy(_param0 *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error)

func (*MockS3API) UploadPartCopyRequest

func (_m *MockS3API) UploadPartCopyRequest(_param0 *s3.UploadPartCopyInput) (*request.Request, *s3.UploadPartCopyOutput)

func (*MockS3API) UploadPartRequest

func (_m *MockS3API) UploadPartRequest(_param0 *s3.UploadPartInput) (*request.Request, *s3.UploadPartOutput)

type S3

type S3 interface {
	ListObjectsV2(input *s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error)
	DeleteObject(input *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error)
	CopyObject(input *s3.CopyObjectInput) (*s3.CopyObjectOutput, error)
	PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error)
	GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, error)
}

type S3Driver

type S3Driver struct {
	// contains filtered or unexported fields
}

func NewS3Driver

func NewS3Driver(
	bucket,
	prefix,
	homePath,
	region,
	awsAccessKeyID,
	awsSecretKey,
	awsToken,
	remoteIPAddress string,
	kmsKeyID *string,
	lg Logger,
) *S3Driver

NewS3Driver creates a new S3Driver with the AWS credentials and S3 parameters. bucket: name of S3 bucket prefix: key within the S3 bucket, if applicable homePath: default home directory for user (can be different from prefix)

func (S3Driver) DeleteDir

func (d S3Driver) DeleteDir(path string) error

func (S3Driver) DeleteFile

func (d S3Driver) DeleteFile(path string) error

func (S3Driver) GetFile

func (d S3Driver) GetFile(path string) (io.ReadCloser, error)

func (S3Driver) ListDir

func (d S3Driver) ListDir(path string) ([]os.FileInfo, error)

func (S3Driver) MakeDir

func (d S3Driver) MakeDir(path string) error

func (S3Driver) PutFile

func (d S3Driver) PutFile(path string, r io.Reader) error

func (S3Driver) RealPath

func (d S3Driver) RealPath(path string) string

func (S3Driver) Rename

func (d S3Driver) Rename(oldpath string, newpath string) error

func (S3Driver) Stat

func (d S3Driver) Stat(path string) (os.FileInfo, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an SSH File Transfer Protocol (sftp) server. This is intended to provide the sftp subsystem to an ssh server daemon. This implementation currently supports most of sftp server protocol version 3, as specified at http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02

func NewServer

func NewServer(rwc io.ReadWriteCloser, driver ServerDriver, options ...ServerOption) (*Server, error)

NewServer creates a new Server instance around the provided streams, serving content from the root of the filesystem. Optionally, ServerOption functions may be specified to further configure the Server.

A subsequent call to Serve() is required to begin serving files over SFTP.

func (*Server) Serve

func (svr *Server) Serve() error

Serve serves SFTP connections until the streams stop or the SFTP subsystem is stopped.

type ServerDriver

type ServerDriver interface {
	Stat(path string) (os.FileInfo, error)
	ListDir(path string) ([]os.FileInfo, error)
	DeleteDir(path string) error
	DeleteFile(path string) error
	Rename(oldPath string, newPath string) error
	MakeDir(path string) error
	GetFile(path string) (io.ReadCloser, error)
	PutFile(path string, reader io.Reader) error
	RealPath(path string) string
}

type ServerOption

type ServerOption func(*Server) error

A ServerOption is a function which applies configuration to a Server.

func ReadOnly

func ReadOnly() ServerOption

ReadOnly configures a Server to serve files in read-only mode.

func WithDebug

func WithDebug(w io.Writer) ServerOption

WithDebug enables Server debugging output to the supplied io.Writer.

type SourceChecker

type SourceChecker func(net.Addr) (bool, error)

SourceChecker can be used to decide whether to trust the PROXY info or pass the original connection address through. If set, the connecting address is passed in as an argument. If the function returns an error due to the source being disallowed, it should return ErrInvalidUpstream.

If error is not nil, the call to Accept() will fail. If the reason for triggering this failure is due to a disallowed source, it should return ErrInvalidUpstream.

If bool is true, the PROXY-set address is used.

If bool is false, the connection's remote address is used, rather than the address claimed in the PROXY info.

type StatExtended

type StatExtended struct {
	ExtType string
	ExtData string
}

StatExtended contains additional, extended information for a FileStat.

type StatVFS

type StatVFS struct {
	ID      uint32
	Bsize   uint64 /* file system block size */
	Frsize  uint64 /* fundamental fs block size */
	Blocks  uint64 /* number of blocks (unit f_frsize) */
	Bfree   uint64 /* free blocks in file system */
	Bavail  uint64 /* free blocks for non-root */
	Files   uint64 /* total file inodes */
	Ffree   uint64 /* free file inodes */
	Favail  uint64 /* free file inodes for to non-root */
	Fsid    uint64 /* file system id */
	Flag    uint64 /* bit mask of f_flag values */
	Namemax uint64 /* maximum filename length */
}

A StatVFS contains statistics about a filesystem.

func (*StatVFS) FreeSpace

func (p *StatVFS) FreeSpace() uint64

FreeSpace calculates the amount of free space in a filesystem.

func (*StatVFS) MarshalBinary

func (p *StatVFS) MarshalBinary() ([]byte, error)

MarshalBinary converts the packet to ssh_FXP_EXTENDED_REPLY packet binary format

func (*StatVFS) TotalSpace

func (p *StatVFS) TotalSpace() uint64

TotalSpace calculates the amount of total space in a filesystem.

type StatusError

type StatusError struct {
	Code uint32
	// contains filtered or unexported fields
}

A StatusError is returned when an SFTP operation fails, and provides additional information about the failure.

func (*StatusError) Error

func (s *StatusError) Error() string

type TestFileDriver

type TestFileDriver struct{}

func (TestFileDriver) DeleteDir

func (d TestFileDriver) DeleteDir(path string) error

func (TestFileDriver) DeleteFile

func (d TestFileDriver) DeleteFile(path string) error

func (TestFileDriver) GetFile

func (d TestFileDriver) GetFile(path string) (io.ReadCloser, error)

func (TestFileDriver) ListDir

func (d TestFileDriver) ListDir(path string) ([]os.FileInfo, error)

func (TestFileDriver) MakeDir

func (d TestFileDriver) MakeDir(path string) error

func (TestFileDriver) PutFile

func (d TestFileDriver) PutFile(path string, r io.Reader) error

func (TestFileDriver) RealPath

func (d TestFileDriver) RealPath(path string) string

func (TestFileDriver) Rename

func (d TestFileDriver) Rename(oldpath string, newpath string) error

func (TestFileDriver) Stat

func (d TestFileDriver) Stat(path string) (os.FileInfo, error)

Directories

Path Synopsis
examples
buffered-read-benchmark
buffered-read-benchmark benchmarks the peformance of reading from /dev/zero on the server to a []byte on the client via io.Copy.
buffered-read-benchmark benchmarks the peformance of reading from /dev/zero on the server to a []byte on the client via io.Copy.
buffered-write-benchmark
buffered-write-benchmark benchmarks the peformance of writing a single large []byte on the client to /dev/null on the server via io.Copy.
buffered-write-benchmark benchmarks the peformance of writing a single large []byte on the client to /dev/null on the server via io.Copy.
sftp-server
An example SFTP server implementation using the golang SSH package.
An example SFTP server implementation using the golang SSH package.
streaming-read-benchmark
streaming-read-benchmark benchmarks the peformance of reading from /dev/zero on the server to /dev/null on the client via io.Copy.
streaming-read-benchmark benchmarks the peformance of reading from /dev/zero on the server to /dev/null on the client via io.Copy.
streaming-write-benchmark
streaming-write-benchmark benchmarks the peformance of writing from /dev/zero on the client to /dev/null on the server via io.Copy.
streaming-write-benchmark benchmarks the peformance of writing from /dev/zero on the client to /dev/null on the server via io.Copy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL