gosftp

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

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

Go to latest
Published: Oct 10, 2015 License: BSD-3-Clause Imports: 10 Imported by: 2

README

gosftp

SFTP client library for Go, bulit on the revised SSH client API

This library is fully functional, but will not likely be receiving updates. Go over to http://github.com/pkg/sftp for an actively maintained library (and the one I will be contributing to).

Documentation

Overview

package sftp provides an SFTP client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides an SFTP client instance.

func NewClient

func NewClient(s *ssh.Session) (*Client, error)

NewClient creates a new SFTP client on top of an already created ssh.Session.

func (*Client) Chmod

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

func (*Client) Chown

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

func (*Client) Close

func (s *Client) Close()

Close closes the SSH session and stops listening for new messages. No further operations may be performed on the instance after calling Close.

func (*Client) LStat

func (s *Client) LStat(path string) (os.FileInfo, error)

LStat returns file attributes for the given path.

func (*Client) Mkdir

func (s *Client) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory at the specified absolute path with the specified permissions.

func (*Client) Open

func (s *Client) Open(name string) (*File, error)

func (*Client) OpenFile

func (s *Client) OpenFile(name string, flags int, attrs os.FileMode) (*File, error)

TODO(ekg): this can actually accept an entire attr structure...

func (*Client) PosixRename

func (s *Client) PosixRename(oldname, newname string) error

func (*Client) Put

func (c *Client) Put(r io.Reader, remote string) (n int64, _ error)

Put is a convenience method that copies data to the remote path, creating the file with default permissions if it does not exist and overwriting it if it does.

func (*Client) ReadDir

func (s *Client) ReadDir(name string) ([]os.FileInfo, error)

ReadDir returns a list of file information for files in a specific directory.

func (s *Client) Readlink(name string) (string, error)

func (*Client) Realpath

func (s *Client) Realpath(path string) (string, error)

func (*Client) Remove

func (s *Client) Remove(name string) error

Remove deletes the named file.

func (*Client) Rename

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

func (*Client) Rmdir

func (s *Client) Rmdir(name string) error

Rmdir deletes the named directory.

func (*Client) Stat

func (s *Client) Stat(path string) (os.FileInfo, error)

Stat returns file attributes for the given path.

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

Symlink creates a symbolic link at the path newname pointing to the path oldname.

type File

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

func (*File) Chown

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

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Read

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

func (*File) ReadAt

func (f *File) ReadAt(b []byte, off int64) (n int, err error)

func (*File) Seek

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

func (*File) Stat

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

func (*File) String

func (f *File) String() string

func (*File) Write

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

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (n int, err error)

type FileAttributes

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

FileAttributes contains information about a particular file. It fulfills the os.FileInfo interface. However, the SFTP specification allows the server to only conditionally include fields if the server supports them. See the function documentation for how this is handled.

func (FileAttributes) IsDir

func (f FileAttributes) IsDir() bool

IsDir returns true if the entity is a directory. If mode was not returned by the server, this method's return value is undefined.

func (FileAttributes) ModTime

func (f FileAttributes) ModTime() time.Time

ModTime returns the modification time of the file. If the time was not returned by the server, this method returns the zero-time.

func (FileAttributes) Mode

func (f FileAttributes) Mode() os.FileMode

Mode returns a file's mode and permission bits. If mode was not returned by the server, this method returns 0.

func (FileAttributes) Name

func (f FileAttributes) Name() string

Name returns the name of the file to which the data applies.

func (FileAttributes) Size

func (f FileAttributes) Size() int64

Size returns the size in bytes of the file. If the size was not returned by the server, -1 is returned.

func (FileAttributes) Sys

func (f FileAttributes) Sys() interface{}

Sys returns the underlying data source of this structure.

type Status

type Status uint32

Status is a error number defined by section 7, "Responses from the Server to the Client".

const (
	OK Status = iota

	NoSuchFile
	PermissionDenied
	Failure
	BadMessage
	NoConnection
	ConnectionLost
	OpUnsupported
)

The list of error codes defined by the protocol.

func GetStatus

func GetStatus(err error) (Status, bool)

GetStatus retrieves the sftp status code inside the sftp error. The second returned value will be false if the given error is not an sftp error.

type UnexpectedMessageError

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

UnexpectedMessageError results when the SSH message that was received did not match what the protocol specifies as the proper returned message type.

func (UnexpectedMessageError) Error

func (u UnexpectedMessageError) Error() string

Jump to

Keyboard shortcuts

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