usftp

package
v0.0.0-...-0865dfd Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT, BSD-2-Clause Imports: 17 Imported by: 0

README

sftp

The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem. It also implements an SFTP server for serving files from the filesystem.

CI Status Go Reference

usage and examples

See https://pkg.go.dev/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.

For API/code bugs, please include a small, self contained code example to reproduce the issue. For pull requests, remember test coverage.

We try to handle issues and pull requests with a 0 open philosophy. That means we will try to address the submission as soon as possible and will work toward a resolution. If progress can no longer be made (eg. unreproducible bug) or stops (eg. unresponsive submitter), we will close the bug.

Thanks.

Documentation

Overview

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

Index

Constants

View Source
const ErrOpenned = uerr.Const("file already openned")
View Source
const S_IFMT = uint32(ModeType)

S_IFMT is a legacy export, and was brought in to support GOOS environments whose sysconfig.S_IFMT may be different from the value used internally by SFTP standards. There should be no reason why you need to import it, or use it, but unexporting it could cause code to break in a way that cannot be readily fixed. As such, we continue to export this value as the value used in the SFTP standard.

Deprecated: Remove use of this value, and avoid any future use as well. There is no alternative provided, you should never need to access this value.

Variables

This section is empty.

Functions

func FileInfoFromStat

func FileInfoFromStat(stat *FileStat, name string) os.FileInfo

convert a FileStat and filename to a go os.FileInfo

func SetSFTPExtensions

func SetSFTPExtensions(extensions ...string) error

SetSFTPExtensions allows to customize the supported server extensions. See the variable supportedSFTPExtensions for supported extensions. This method accepts a slice of sshExtensionPair names for example 'hardlink@openssh.com'. If an invalid extension is given an error will be returned and nothing will be changed

Types

type AsyncFunc

type AsyncFunc func(req any, err error)

Callback invoked upon completion of an async operation.

This is useful to avoid waiting for responses before starting the next operation. For example, a pipeline where a file is opened async, could feed a chan to a worker that then writes to the open file and async closes it, which then feeds a chan for a worker that gets the close disposition.

Any work performed in the callback should be brief and non blocking, offloading any time consuming or blocking work to a separate goroutine. This callback will be called in the event loop of the connection reader, so delaying return delays reading the next message.

If nil, then the async operation is "fire and forget". This is useful (for example) after closing a File that is open for reading, but dangerous (for example) after closing a file that is open for writing.

The req is provided by the caller as "callback data".

The error is the disposition of the async operation. If nil, then the operation was successful.

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.

func NewClient

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

Create a new SFTP client on the SSH client conn

func NewClientPipe

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

Create a new SFTP client with the 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).

func (*Client) Chmod

func (client *Client) Chmod(pathN string, mode os.FileMode) error

Change the permissions of the named file.

No umask will be applied. Because even retrieving the umask is not possible in a portable way without causing a race condition. Callers should mask off umask bits, if desired.

func (*Client) Chown

func (client *Client) Chown(pathN string, uid, gid int) error

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

func (*Client) Chtimes

func (client *Client) Chtimes(pathN string, atime time.Time, mtime time.Time) error

Change the access and modification times of the named file.

func (*Client) Close

func (client *Client) Close() error

close connection to SFTP server and cease operation

func (*Client) Create

func (client *Client) Create(pathN string) (*File, error)

Create 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. If you need more control over the flags/mode used to open the file see client.OpenFile.

Note that some SFTP servers (eg. AWS Transfer) do not support opening files read/write at the same time. For those services you will need to use `client.OpenFile(os.O_WRONLY|os.O_CREATE|os.O_TRUNC)`.

func (*Client) CreateAsync

func (client *Client) CreateAsync(
	pathN string, req any, onComplete AsyncFunc,
) (f *File, err error)

Create the file, async.

func (*Client) FS

func (client *Client) FS() fs.FS

return fs.FS compliant facade

func (*Client) Getwd

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

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

func (*Client) HasExtension

func (client *Client) HasExtension(name string) (string, bool)

Check whether the server supports a named extension.

The first return value is the extension data reported by the server (typically a version number).

func (client *Client) Link(oldname, newname string) error

Link creates a hard link at 'newname', pointing at the same inode as 'oldname'

func (*Client) Lstat

func (client *Client) Lstat(pathN string) (attrs *FileStat, err error)

Return a FileStat describing the file specified by pathN. If pathN is a symbolic link, the returned FileStat describes the link, not the actual file.

func (*Client) Mkdir

func (client *Client) Mkdir(dirN string) error

Create 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) MkdirAll

func (client *Client) MkdirAll(dirN string) (err error)

Create the dirN directory, along with any necessary parents. If dirN exists and is a directory, do nothing and return nil. If dirN exists and is not a directory, return error.

func (*Client) Open

func (client *Client) Open(pathN string, flags int) (*File, error)

Open file at path using the specified flags

func (*Client) OpenAsync

func (client *Client) OpenAsync(
	pathN string, flags int, req any, onComplete AsyncFunc,
) (f *File, err error)

Open file at path using the specified flags, async

func (*Client) OpenRead

func (client *Client) OpenRead(pathN string) (*File, error)

Open file at pathN for reading.

func (*Client) OpenReadAsync

func (client *Client) OpenReadAsync(
	pathN string, req any, onComplete AsyncFunc,
) (f *File, err error)

Open file at pathN for reading, async.

func (*Client) PosixRename

func (client *Client) PosixRename(oldN, newN string) error

Rename oldN to newN, replacing newN if it exists. Uses the posix-rename@openssh.com extension.

func (*Client) PosixRenameAsync

func (client *Client) PosixRenameAsync(
	oldN, newN string,
	req any,
	onComplete AsyncFunc,
) (err error)

Rename oldN to newN, replacing newN if it exists, async. Uses the posix-rename@openssh.com extension.

func (*Client) ReadDir

func (client *Client) ReadDir(dirN string) ([]*File, error)

Get a list of Files in dirN.

Due to SFTP, it takes at least 3 round trips with the server to get a listing of the files.

func (*Client) ReadDirLimit

func (client *Client) ReadDirLimit(
	dirN string,
	timeout time.Duration,
	filter ReadDirFilter,
) (
	entries []*File,
	err error,
)

Get a list of Files in dirN.

Due to SFTP, it takes at least 3 round trips with the server to get a listing of the files.

func (client *Client) ReadLink(pathN string) (target string, err error)

Read the target of a symbolic link (resolve to actual file/dir).

func (*Client) RealPath

func (client *Client) RealPath(pathN string) (canonN string, err error)

Request server to canonicalize pathN to an absolute path.

This is useful for converting path names containing ".." components, or relative pathnames without a leading slash into absolute paths.

func (*Client) Remove

func (client *Client) Remove(pathN string) error

Remove pathN. Return error if pathN does not exist, or if pathN is a non-empty directory.

func (*Client) RemoveAll

func (client *Client) RemoveAll(dirN string) (err error)

Delete dirN and all files (if dirN is a dir) of any kind contained in dirN.

This will error if dirN does not exist.

func (*Client) RemoveAllIn

func (client *Client) RemoveAllIn(dirN string) (err error)

Delete all files contained in dirN, but do not delete dirN.

func (*Client) RemoveAsync

func (client *Client) RemoveAsync(
	pathN string,
	req any,
	onComplete AsyncFunc,
) error

func (*Client) RemoveDirectory

func (client *Client) RemoveDirectory(pathN string) error

RemoveDirectory removes a directory path.

func (*Client) Rename

func (client *Client) Rename(oldN, newN string) error

Rename oldN to newN, error if newN exists.

func (*Client) RenameAsync

func (client *Client) RenameAsync(
	oldN, newN string,
	req any,
	onComplete AsyncFunc,
) (err error)

Rename oldN to newN, async.

func (*Client) SetExtendedAttr

func (client *Client) SetExtendedAttr(pathN string, ext []StatExtended) error

Set extended attributes of the named file, using the SSH_FILEXFER_ATTR_EXTENDED flag in the setstat request.

This flag provides a general extension mechanism for vendor-specific extensions. Names of the attributes should be a string of the format "name@domain", where "domain" is a valid, registered domain name and "name" identifies the method. Server implementations SHOULD ignore extended data fields that they do not understand.

func (*Client) Stat

func (client *Client) Stat(pathN string) (fs *FileStat, err error)

Return a FileStat describing the file specified by pathN If pathN is a symbolic link, the returned FileStat describes the actual file, not the link.

func (*Client) StatVFS

func (client *Client) StatVFS(pathN string) (rv *StatVFS, err error)

get VFS (file system) statistics from a remote host.

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

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

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

func (*Client) Truncate

func (client *Client) Truncate(pathN string, size int64) error

Set the size of the named file. Setting a size smaller than the current size causes file truncation. Setting a size greater than the current size is not defined by SFTP - the server may grow the file or do something else.

func (*Client) WalkDir

func (client *Client) WalkDir(rootD string, f fs.WalkDirFunc) error

see fs.WalkDir

type ClientOption

type ClientOption func(*Client) error

A ClientOption is a function which applies configuration to a Client.

func WithErrorFunc

func WithErrorFunc(onError func(error)) ClientOption

Add a func to receive async error notifications. These can occur if the connection to the SFTP server is lost, for example.

The func should not perform time consuming operations. One or more invocations may occur on connection failure.

func WithMaxPacket

func WithMaxPacket(size int) ClientOption

Set the maximum size (bytes) of the payload.

The larger the payload, the more efficient the transport.

The default is 32768 (32KiB), which all compliant SFTP servers must support. - OpenSsh supports 255KiB (version 8.7 was used for the test)

If you get the error "failed to send packet header: EOF" when copying a large file, try lowering this number.

func WithWriteToStrategy

func WithWriteToStrategy(strategy WriteToStrategy) ClientOption

Specify what File.WriteTo should do to determine the File size. Default is WriteToNever, which is to return an errof if the File's attributes are not known before the call.

refer to File.WriteTo

type FS

type FS interface {
	fs.FS
	fs.ReadDirFS
	fs.StatFS
}

implement fs interfaces

type File

type File struct {
	Stash any // stash whatever you want here
	// contains filtered or unexported fields
}

Provide access to a remote file.

Files obtained via Client.ReadDir are not in an open state. They must be opened first. These Files do have populated attributes.

Files obtained via Client.Open calls are open, but do not have populated attributes until Stat() is called.

Calls that change the offset (Read/ReadFrom/Write/WriteTo/Seek) need to be externally coordinated or synchronized. This is no different than dealing with any other kind of file, as concurrent reads and writes will result in gibberish otherwise.

Likewise, Open/Close needs to also be externally coordinated or synchronized with other i/o ops.

func NewFile

func NewFile(client *Client, pathN string) *File

normally create with client.Open or client.ReadDir

func (*File) AttrsCached

func (f *File) AttrsCached() bool

return true if attributes are populated

func (*File) BaseName

func (f *File) BaseName() string

return the base name of the file

func (*File) Chmod

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

Change the permissions of the current file.

See Client.Chmod for details.

func (*File) Chown

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

Change the uid/gid of the current file.

async safe

func (*File) Client

func (f *File) Client() *Client

func (*File) Close

func (f *File) Close() error

implement io.Closer

close the File.

syncronize access

func (*File) CloseAsync

func (f *File) CloseAsync(req any, onComplete AsyncFunc) error

close the File, async.

Use nil for request and respC to "fire and forget". This is useful when closing after an error encountered or for done reading, but dangerous after a successful write, as it is possible the write is not 100% complete and a failure is detected during close.

syncronize access

func (*File) FileStat

func (f *File) FileStat() FileStat

return cached FileStat, which may not be populated with file attributes.

if Mode bits are zero, then it is not populated.

it will be populated after a ReadDir, or a Stat call

func (*File) IsDir

func (f *File) IsDir() bool

if attrs are populated, check if this is a dir

func (*File) IsOpen

func (f *File) IsOpen() bool

func (*File) IsRegular

func (f *File) IsRegular() bool

if attrs are populated, check if this is regular file

func (*File) ModTime

func (f *File) ModTime() time.Time

careful - this creates a time.Time each invocation

func (*File) ModTimeUnix

func (f *File) ModTimeUnix() uint32

if attrs are populated, mod time in unix serespConds

it's only 32 bits, but it's unsigned so will not fail in 2038

func (*File) Mode

func (f *File) Mode() FileMode

if attrs are populated, mode bits of file. otherwise, bits are zero.

func (*File) Name

func (f *File) Name() string

return the name of the file as presented to Open or Create.

func (*File) Open

func (f *File) Open(flags int) (err error)

Open file using the specified flags

async safe

func (*File) OpenAsync

func (f *File) OpenAsync(flags int, req any, onComplete AsyncFunc) (err error)

Open the file, async.

async safe

func (*File) OpenRead

func (f *File) OpenRead() (err error)

Open the file for read.

async safe

func (*File) OpenReadAsync

func (f *File) OpenReadAsync(req any, onComplete AsyncFunc) (err error)

Open the file for read, async.

async safe

func (*File) PosixRename

func (f *File) PosixRename(newN string) (err error)

rename file, even if newN already exists (replacing it).

uses the posix-rename@openssh.com extension

synchronize access

func (*File) PosixRenameAsync

func (f *File) PosixRenameAsync(newN string, req any, onComplete AsyncFunc) error

rename file, async, even if newN already exists (replacing it).

uses the posix-rename@openssh.com extension

synchronize access

func (*File) Read

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

implement io.Reader

Reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any. When Read encounters an error or EOF respCondition after successfully reading n > 0 bytes, it returns the number of bytes read.

The read may be broken up into chunks supported by the server.

If transfering to an io.Writer, use WriteTo for best performance. io.Copy will do this automatically.

synchronize i/o ops

func (*File) ReadAt

func (f *File) ReadAt(toBuff []byte, offset int64) (nread int, err error)

implement io.ReaderAt. Read up to len toBuff bytes from file at current offset, leaving offset unchanged.

synchronize i/o ops

func (*File) ReadFrom

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

implement io.ReaderFrom

Copy from io.Reader into this file starting at current offset.

synchronize i/o ops

func (*File) Remove

func (f *File) Remove() (err error)

remove the file. it may remain open.

async safe

func (*File) RemoveAsync

func (f *File) RemoveAsync(req any, onComplete AsyncFunc) error

remove the file, async. it may remain open.

async safe

func (*File) Rename

func (f *File) Rename(newN string) (err error)

rename file.

synchronize access

func (*File) RenameAsync

func (f *File) RenameAsync(newN string, req any, onComplete AsyncFunc) error

Rename file, but only if it doesn't already exist.

synchronize access

func (*File) Seek

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

implement io.Seeker

Set the offset for the next Read or Write. Return the next offset.

Seeking before or after the end of the file is undefined.

Seeking relative to the end will call Stat if file has no cached attributes, otherwise, it will use the cached attributes.

synchronize i/o ops

func (*File) SetClient

func (f *File) SetClient(c *Client) error

if File is not currently open, it is possible to change the Client

func (*File) SetExtendedData

func (f *File) SetExtendedData(path string, extended []StatExtended) error

SetExtendedData sets extended attributes of the current file. It uses the SSH_FILEXFER_ATTR_EXTENDED flag in the setstat request.

This flag provides a general extension mechanism for vendor-specific extensions. Names of the attributes should be a string of the format "name@domain", where "domain" is a valid, registered domain name and "name" identifies the method. Server implementations SHOULD ignore extended data fields that they do not understand.

async safe

func (*File) SetName

func (f *File) SetName(newN string)

change the name

func (*File) Size

func (f *File) Size() uint64

if attrs are populated, size of the file

func (*File) Stat

func (f *File) Stat() (attrs *FileStat, err error)

Stat returns the attributes about the file. If the file is open, then fstat is used, otherwise, stat is used. The attributes cached in this File will be updated. To avoid a round trip with the server, use the already cached FileStat.

synchronize i/o ops

func (*File) Sync

func (f *File) Sync() error

Request a flush of the contents of a File to stable storage.

Sync requires the server to support the fsync@openssh.com extension.

async safe

func (*File) SyncAsync

func (f *File) SyncAsync(req any, onComplete AsyncFunc) error

Asynchronously request a flush of the contents of a File to stable storage.

Requires the server to support the fsync@openssh.com extension.

async safe

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.

async safe

func (*File) Write

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

implement io.Writer. Write bytes to file, appending at current offset.

synchronize i/o ops

func (*File) WriteAt

func (f *File) WriteAt(dataB []byte, offset int64) (written int, err error)

implement io.WriterAt. Write bytes to file at current offset, leaving offset unchanged.

synchronize i/o ops

func (*File) WriteTo

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

implement io.WriterTo

copy contents (from current offset to end) of file to w

If File is not known (File was not built from ReadDir, or no Stat call was placed prior to this), then WriteTo might return an error, depending on the WriteToStrategy ClientOption set on the Client.

synchronize i/o ops

type FileInfoExtendedData

type FileInfoExtendedData interface {
	os.FileInfo
	Extended() []StatExtended
}

FileInfoUidGid extends os.FileInfo and adds a callbacks for extended data retrieval.

type FileInfoUidGid

type FileInfoUidGid interface {
	os.FileInfo
	Uid() uint32
	Gid() uint32
}

FileInfoUidGid extends os.FileInfo and adds callbacks for Uid and Gid retrieval, as an alternative to *syscall.Stat_t objects on unix systems.

type FileMode

type FileMode uint32

FileMode represents a file’s mode and permission bits. The bits are defined according to POSIX standards, and may not apply to the OS being built for.

const (
	ModePerm       FileMode = 0o0777 // S_IRWXU | S_IRWXG | S_IRWXO
	ModeUserRead   FileMode = 0o0400 // S_IRUSR
	ModeUserWrite  FileMode = 0o0200 // S_IWUSR
	ModeUserExec   FileMode = 0o0100 // S_IXUSR
	ModeGroupRead  FileMode = 0o0040 // S_IRGRP
	ModeGroupWrite FileMode = 0o0020 // S_IWGRP
	ModeGroupExec  FileMode = 0o0010 // S_IXGRP
	ModeOtherRead  FileMode = 0o0004 // S_IROTH
	ModeOtherWrite FileMode = 0o0002 // S_IWOTH
	ModeOtherExec  FileMode = 0o0001 // S_IXOTH

	ModeSetUID FileMode = 0o4000 // S_ISUID
	ModeSetGID FileMode = 0o2000 // S_ISGID
	ModeSticky FileMode = 0o1000 // S_ISVTX

	ModeType       FileMode = 0xF000 // S_IFMT
	ModeNamedPipe  FileMode = 0x1000 // S_IFIFO
	ModeCharDevice FileMode = 0x2000 // S_IFCHR
	ModeDir        FileMode = 0x4000 // S_IFDIR
	ModeDevice     FileMode = 0x6000 // S_IFBLK
	ModeRegular    FileMode = 0x8000 // S_IFREG
	ModeSymlink    FileMode = 0xA000 // S_IFLNK
	ModeSocket     FileMode = 0xC000 // S_IFSOCK
)

Permission flags, defined here to avoid potential inconsistencies in individual OS implementations.

func (FileMode) IsDir

func (m FileMode) IsDir() bool

IsDir reports whether m describes a directory. That is, it tests for m.Type() == ModeDir.

func (FileMode) IsRegular

func (m FileMode) IsRegular() bool

IsRegular reports whether m describes a regular file. That is, it tests for m.Type() == ModeRegular

func (FileMode) Perm

func (m FileMode) Perm() FileMode

Perm returns the POSIX permission bits in m (m & ModePerm).

func (FileMode) Type

func (m FileMode) Type() FileMode

Type returns the type bits in m (m & ModeType).

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(). It is also used server side to store the unmarshalled values for SetStat.

func (*FileStat) AccessTime

func (fs *FileStat) AccessTime() time.Time

AccessTime returns the Atime SFTP file attribute converted to a time.Time

func (*FileStat) FileMode

func (fs *FileStat) FileMode() FileMode

returns the FileMode, containing type and permission bits

func (*FileStat) FileType

func (fs *FileStat) FileType() FileMode

returns the Type bits of the FileMode

func (*FileStat) IsDir

func (fs *FileStat) IsDir() bool

returns true if the mode describes a directory

func (*FileStat) IsRegular

func (fs *FileStat) IsRegular() bool

returns true if the mode describes a regular file.

func (*FileStat) ModTime

func (fs *FileStat) ModTime() time.Time

ModTime returns the Mtime SFTP file attribute converted to a time.Time

func (*FileStat) OsFileMode

func (fs *FileStat) OsFileMode() os.FileMode

returns the Mode SFTP file attribute converted to an os.FileMode

type ReadDirFilter

type ReadDirFilter func(fileN string, attrs *FileStat) (allow, stop bool)

return allow=true to allow file, stop=true to stop making server reqs

type ReadDirLimit

type ReadDirLimit struct {
	N int
}

func (*ReadDirLimit) Filter

func (rdl *ReadDirLimit) Filter(fileN string, attrs *FileStat) (allow, stop bool)

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) 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 WriteToStrategy

type WriteToStrategy uint8

Strategy for File.WriteTo

const (
	// When File.WriteTo is called, if the File size is known (File was created
	// from ReadDir, or had Stat called prior), then assume the size is correct and
	// proceed.  Otherwise, return an error.
	//
	// This is the default strategy.
	WriteToNeverStat WriteToStrategy = 0

	// When File.WriteTo is called, always issue a Stat call to the server to get
	// the curent File size, even if the size is already known.
	WriteToAlwaysStat WriteToStrategy = 1

	// When File.WriteTo is called, if the File size is not known, issue a Stat
	// call to the server to get it before proceeding.  Otherwise, use the cached
	// size.
	WriteToLazyStat WriteToStrategy = 2
)

Jump to

Keyboard shortcuts

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