ftps

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: ISC Imports: 14 Imported by: 0

README

FTPS Implementation for Go

Information

This implementation does not implement the full FTP/FTPS specification. Only a small subset.

I have not done a security review of the code, yet. Therefore no guarantee is given. It would be nice if somebody could do a security review and report back if the implementation is vulnerable.

Installation

go get github.com/webguerilla/ftps

Usage

ftps := new(FTPS)

ftps.TLSConfig.InsecureSkipVerify = true // often necessary in shared hosting environments
ftps.Debug = true

err := ftps.Connect("localhost", 21)
if err != nil {
	panic(err)
}

err = ftps.Login("username", "password")
if err != nil {
	panic(err)
}

directory, err := ftps.PrintWorkingDirectory()
if err != nil {
	panic(err)
}
log.Printf("Current working directory: %s", directory)

err = ftps.Quit()
if err != nil {
	panic(err)
}

Credits

This work was inspired by the work of jlaffaye (https://github.com/jlaffaye/ftp) and smallfish (https://github.com/smallfish/ftp).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UserName string
	Password string
	Host     string
}

Client FTPS Client

func NewClient

func NewClient(user string, pass string, host string) *Client

NewClient return new FTPS Client

func (*Client) Download

func (c *Client) Download(filePath string) error

Download file from server

func (*Client) DownloadFile

func (c *Client) DownloadFile(file *os.File) error

DownloadFile file from server

func (*Client) DownloadWriter

func (c *Client) DownloadWriter(writer io.Writer) error

DownloadFile file from server

func (*Client) Upload

func (c *Client) Upload(filePath string) error

Upload file to Server

func (*Client) UploadFile

func (c *Client) UploadFile(remoteFilepath string, file *os.File) error

UploadFile file to Server

func (*Client) UploadReader

func (c *Client) UploadReader(remoteFilepath string, source io.Reader) error

UploadFile file to Server

type Entry

type Entry struct {
	Type EntryType
	Name string
	Size uint64
	Time time.Time
}

type EntryType

type EntryType int
const (
	EntryTypeFile EntryType = iota
	EntryTypeFolder
	EntryTypeLink
)

type FTPS

type FTPS struct {
	Debug     bool
	TLSConfig tls.Config
	SendDone  chan bool
	// contains filtered or unexported fields
}

func (*FTPS) ChangeWorkingDirectory

func (ftps *FTPS) ChangeWorkingDirectory(path string) (err error)

func (*FTPS) Connect

func (ftps *FTPS) Connect(host string, port int, isImplicit bool) (err error)

func (*FTPS) DeleteFile

func (ftps *FTPS) DeleteFile(path string) (err error)

func (*FTPS) List

func (ftps *FTPS) List() (entries []Entry, err error)

func (*FTPS) Login

func (ftps *FTPS) Login(username, password string) (err error)

func (*FTPS) MakeDirectory

func (ftps *FTPS) MakeDirectory(path string) (err error)

func (*FTPS) Noop

func (ftps *FTPS) Noop() (err error)

func (*FTPS) PrintWorkingDirectory

func (ftps *FTPS) PrintWorkingDirectory() (directory string, err error)

func (*FTPS) PutFile

func (ftps *FTPS) PutFile(remoteFilepath string, f *os.File) (err error)

func (*FTPS) Quit

func (ftps *FTPS) Quit() (err error)

func (*FTPS) RemoveDirectory

func (ftps *FTPS) RemoveDirectory(path string) (err error)

func (*FTPS) Rename

func (ftps *FTPS) Rename(from, to string) error

Rename renames a file on the remote FTPS server.

func (*FTPS) RetrieveFile

func (ftps *FTPS) RetrieveFile(remoteFilepath string, file *os.File) (err error)

func (*FTPS) RetrieveFileData

func (ftps *FTPS) RetrieveFileData(remoteFilepath string) (data []byte, err error)

func (*FTPS) RetrieveWriter

func (ftps *FTPS) RetrieveWriter(remoteFilepath string, w io.Writer) (err error)

func (*FTPS) SizeFile

func (ftps *FTPS) SizeFile(path string) (res string, err error)

func (*FTPS) StoreFile

func (ftps *FTPS) StoreFile(remoteFilepath string, f *os.File) (err error)

func (*FTPS) StoreReader

func (ftps *FTPS) StoreReader(remoteFilepath string, r io.Reader) (err error)
func shutdownWrite(conn net.Conn) {
    // anonymous interface. Could explicitly use TCP instead.
    if v, ok := conn.(interface{ CloseWrite() error }); ok {
        v.CloseWrite()
    }
}
func (ftps *FTPS) WaitClose(c net.Conn) {
    one := make([]byte, 1)
    c.SetReadDeadline(time.Now())
    for true {
        if _, err := c.Read(one); err == io.EOF {
            c.Close()
            c = nil
            ftps.SendDone <- true
        } else {
            c.SetReadDeadline(time.Now().Add(10 * time.Millisecond))
        }
    }
}

Jump to

Keyboard shortcuts

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