ftp

package module
v0.0.0-...-1b8497e Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 12 Imported by: 0

README

FTP

This package allows a smooth use of FTP

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Addr     = flag.String("ftp-addr", "", "the ftp addr")
	Password = flag.String("ftp-password", "", "the ftp password")
	Timeout  = flag.Duration("ftp-timeout", 0, "the ftp timeout")
	Username = flag.String("ftp-username", "", "the ftp username")
)

Flags

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Addr     string        `json:"addr"`
	Password string        `json:"password"`
	Timeout  time.Duration `toml:"timeout"`
	Username string        `json:"username"`
}

Configuration represents the FTP configuration

func FlagConfig

func FlagConfig() Configuration

FlagConfig generates a Configuration based on flags

type Dialer

type Dialer interface {
	Dial(addr string) (conn ServerConnexion, err error)
	DialTimeout(addr string, timeout time.Duration) (conn ServerConnexion, err error)
}

func NewDefaultDialer

func NewDefaultDialer() Dialer

Comment

type FTP

type FTP struct {
	Addr     string
	Password string
	Timeout  time.Duration
	Username string
	// contains filtered or unexported fields
}

FTP represents an FTP

func New

func New(c Configuration, dialer Dialer) *FTP

New creates a new FTP connection based on a configuration

func (*FTP) Connect

func (f *FTP) Connect() (conn ServerConnexion, err error)

Connect connects to the FTP and logs in

func (*FTP) CreateDir

func (f *FTP) CreateDir(sPath string) (err error)

CreateDir do

func (*FTP) CreateFile

func (f *FTP) CreateFile(sPath string, reader io.Reader) error

CreateFile in folder with content in param

func (*FTP) Download

func (f *FTP) Download(ctx context.Context, src, dst string) (err error)

Download downloads a file from the remote server

func (*FTP) DownloadReader

func (f *FTP) DownloadReader(src string) (conn ServerConnexion, r io.ReadCloser, err error)

DownloadReader returns the reader built from the download of a file

func (*FTP) Exists

func (f *FTP) Exists(sFilePath string) (b bool, err error)

Exists do

func (*FTP) FileSize

func (f *FTP) FileSize(src string) (s int64, err error)

FileSize do

func (*FTP) GetExtensionFile

func (f *FTP) GetExtensionFile(oFile *ftp.Entry) string

GetExtensionFile do

func (*FTP) GetFileNameWithoutExtension

func (f *FTP) GetFileNameWithoutExtension(sFileName string) string

GetFileNameWithoutExtension do

func (*FTP) List

func (f *FTP) List(sFolder string, aExtensionsAllowed []string, sPattern string) []*ftp.Entry

List do

func (*FTP) ListFolders

func (f *FTP) ListFolders(sFolder string) []*ftp.Entry

ListFolders do

func (*FTP) Remove

func (f *FTP) Remove(src string) (err error)

Remove removes a file

func (*FTP) RemoveDir

func (f *FTP) RemoveDir(sPath string) (err error)

RemoveDir do

func (*FTP) RemoveDirRecur

func (f *FTP) RemoveDirRecur(sPath string) (err error)

RemoveDirRecur do

func (*FTP) Rename

func (f *FTP) Rename(sSource string, sDestination string) (err error)

Rename do

func (*FTP) Upload

func (f *FTP) Upload(ctx context.Context, src, dst string) (err error)

Upload uploads a source path content to a destination

func (*FTP) UploadReader

func (f *FTP) UploadReader(ctx context.Context, reader io.Reader, dst string) error

UploadReader uploads a reader content to a destination

type ServerConnexion

type ServerConnexion interface {
	Login(sUsername string, sPwd string) error
	Retr(path string) (*ftp.Response, error)
	FileSize(path string) (int64, error)
	Stor(path string, oReader io.Reader) error
	MakeDir(sSource string) error
	RemoveDir(sSource string) error
	RemoveDirRecur(sSource string) error
	Rename(sSource string, sDestination string) error
	Delete(oath string) error
	Quit() error
	List(sPath string) ([]*ftp.Entry, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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