tinyftp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: BSD-2-Clause Imports: 10 Imported by: 2

README

tinyftp.go

A small FTP package go language, it uses the net/textproto package for most of the communication.

Currently only passive operation is supported, and the connection management is mostly outside of the package to allow using it with the appengine/socket package.

Documentation

Overview

Package tinyftp implements a small subset of FTP, enough to retrieve directory listings and files (including resume support). It uses net/textproto to do the heavy lifting. Most of the functions return the triple code, message, err besides the real result. if err == nil, code and message return the raw informal FTP server code and message for the success case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

func Dial

func Dial(network, addr string) (conn *Conn, code int, message string, err error)

Dial connects to the given address on the given network using net.Dial and then returns a new Conn for the connection.

func DialTimeout

func DialTimeout(network, addr string, timeout time.Duration) (conn *Conn, code int, message string, err error)

DialTimeout connects to the given address on the given network with a timeout and then returns a new Conn for the connection.

func NewConn

func NewConn(nconn io.ReadWriteCloser) (conn *Conn, code int, message string, err error)

NewConn returns a new Conn using nconn for I/O.

func (*Conn) AuthSSL

func (c *Conn) AuthSSL(mode string) (code int, message string, err error)

"AUTH SSL" command to start SSL/TLS on connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Cmd

func (c *Conn) Cmd(expectCode int, format string, args ...interface{}) (code int, message string, err error)

Send an FTP command and return the response code and message. The expectCode is given as argument to textproto.ReadResponse to signify the expected FTP response code.

func (*Conn) Cwd

func (c *Conn) Cwd(dir string) (code int, message string, err error)

Change the working directory.

func (*Conn) List

func (c *Conn) List(dir string, dconn net.Conn) (dirList []string, code int, message string, err error)

List the specified directory.

func (*Conn) Login

func (c *Conn) Login(user, pass string) (code int, message string, err error)

Authenticate the session using the given user name and password. Use anonymous@ if they are empty.

func (*Conn) NameList

func (c *Conn) NameList(dir string, dconn net.Conn) (dirList []string, code int, message string, err error)

List the specified directory, names only.

func (*Conn) Passive

func (c *Conn) Passive() (addr string, code int, message string, err error)

Enter passive mode, the addr returned is suitable for net.Dial.

func (*Conn) Quit

func (c *Conn) Quit() (code int, message string, err error)

Terminate the FTP session.

func (*Conn) Rest

func (c *Conn) Rest(size int64) (code int, message string, err error)

Start next transfer at the given size

func (*Conn) Retrieve

func (c *Conn) Retrieve(fname string, dconn net.Conn) (contents []byte, code int, message string, err error)

Retrieve the named file

func (*Conn) RetrieveTo

func (c *Conn) RetrieveTo(fname string, dconn net.Conn, w io.Writer) (written int64, code int, message string, err error)

Retrieve the named file to the given io.Writer.

func (*Conn) Size

func (c *Conn) Size(fname string) (size int64, code int, message string, err error)

Return the size of the given file

func (*Conn) SwitchTo

func (c *Conn) SwitchTo(nconn io.ReadWriteCloser)

Switch underlaying connection to a new instance. (Necessary to handle SSL/TLS connections for explicit FTPS servers)

func (*Conn) Type

func (c *Conn) Type(mode string) (code int, message string, err error)

Set the FTP file transfer type (eg. A or I)

func (*Conn) Upload

func (c *Conn) Upload(fname string, dconn net.Conn, contents []byte) (written int64, code int, message string, err error)

Upload the named file

func (*Conn) UploadFrom

func (c *Conn) UploadFrom(fname string, dconn net.Conn, r io.Reader) (written int64, code int, message string, err error)

Upload the named file from the given io.Reader

Jump to

Keyboard shortcuts

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