ftp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package ftp is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfRange = errors.New("out of range")
)

Functions

func New

New initializes a new instance of FTP fileSystem with provided configuration.

Types

type Config

type Config struct {
	Host        string        // FTP server hostname
	User        string        // FTP username
	Password    string        // FTP password
	Port        int           // FTP port
	RemoteDir   string        // Remote directory path. Base Path for all FTP Operations.
	DialTimeout time.Duration // FTP connection timeout
}

Config represents the FTP configuration.

type Conn

type Conn struct {
	*ftp.ServerConn
}

Conn struct embeds the *ftp.ServerConn returned by ftp server on successful connection.

func (*Conn) Retr

func (c *Conn) Retr(filepath string) (ftpResponse, error)

Retr wraps the ftp retrieve method to return a ftpResponse interface type.

func (*Conn) RetrFrom

func (c *Conn) RetrFrom(filepath string, offset uint64) (ftpResponse, error)

type File added in v0.2.0

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

File represents a file on an FTP server.

func (*File) Close added in v0.2.0

func (f *File) Close() error

Close closes the FTP file connection.

func (*File) IsDir added in v0.2.0

func (f *File) IsDir() bool

IsDir checks, if the file is a directory or not. Note: IsDir must be used post Stat/ReadDir methods of fileSystem only.

func (*File) ModTime added in v0.2.0

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

ModTime returns the last time the file/directory was modified. Note: ModTime must be used post Stat/ReadDir methods of fileSystem only.

func (*File) Mode added in v0.2.0

func (f *File) Mode() os.FileMode

Mode checks the FileMode. FTP server doesn't support file modes. This method is to comply with the generalized FileInfo interface.

func (*File) Name added in v0.2.0

func (f *File) Name() string

Name returns the name of the file.

func (*File) Read added in v0.2.0

func (f *File) Read(p []byte) (n int, err error)

Read reads data from the FTP file into the provided byte slice and updates the file offset.

func (*File) ReadAll added in v0.2.0

func (f *File) ReadAll() (file_interface.RowReader, error)

ReadAll reads either JSON or text files based on file extension and returns a corresponding RowReader.

func (*File) ReadAt added in v0.2.0

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

ReadAt reads data from the FTP file starting at the specified offset.

func (*File) Seek added in v0.2.0

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

Seek sets the offset for the next Read/ Write operations.

func (*File) Size added in v0.2.0

func (f *File) Size() int64

Size returns the size of the file.

func (*File) Write added in v0.2.0

func (f *File) Write(p []byte) (n int, err error)

Write writes data to the FTP file.

func (*File) WriteAt added in v0.2.0

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

WriteAt writes data to the FTP file starting at the specified offset.

type FileLog

type FileLog struct {
	Operation string  `json:"operation"`
	Duration  int64   `json:"duration"`
	Status    *string `json:"status"`
	Location  string  `json:"location,omitempty"`
	Message   *string `json:"message,omitempty"`
}

FileLog handles logging with different levels.

func (*FileLog) PrettyPrint

func (fl *FileLog) PrettyPrint(writer io.Writer)

type FileSystem added in v0.2.0

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

FileSystem represents a file system interface over FTP.

func (*FileSystem) ChDir added in v0.2.0

func (f *FileSystem) ChDir(dir string) error

ChDir takes the relative path as argument and changes the current directory.

func (*FileSystem) Connect added in v0.2.0

func (f *FileSystem) Connect()

Connect establishes a connection to the FTP server and logs in.

func (*FileSystem) Create added in v0.2.0

func (f *FileSystem) Create(name string) (file_interface.File, error)

Create creates an empty file on the FTP server.

func (*FileSystem) Getwd added in v0.2.0

func (f *FileSystem) Getwd() (string, error)

Getwd returns the full path of the current directory.

func (*FileSystem) Mkdir added in v0.2.0

func (f *FileSystem) Mkdir(name string, _ os.FileMode) error

Mkdir creates a directory on the FTP server. Here, os.FileMode is unused, but is added to comply with FileSystem interface.

func (*FileSystem) MkdirAll added in v0.2.0

func (f *FileSystem) MkdirAll(name string, _ os.FileMode) error

MkdirAll creates directories recursively on the FTP server. Here, os.FileMode is unused, but is added to comply with FileSystem interface.

func (*FileSystem) Open added in v0.2.0

func (f *FileSystem) Open(name string) (file_interface.File, error)

Open retrieves a file from the FTP server and returns a file handle. Note: Here Open and OpenFile both methods have been implemented so that the FTP FileSystem comply with the gofr FileSystem interface.

func (*FileSystem) OpenFile added in v0.2.0

func (f *FileSystem) OpenFile(name string, _ int, _ os.FileMode) (file_interface.File, error)

OpenFile retrieves a file from the FTP server and returns a file handle. Permissions are not clear for Ftp as file commands do not accept an argument and don't store their file permissions. currently, this function just calls the Open function. Here, os.FileMode is unused, but is added to comply with FileSystem interface.

func (*FileSystem) ReadDir added in v0.2.0

func (f *FileSystem) ReadDir(dir string) ([]file_interface.FileInfo, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error. It returns the list of files/directories present in the current directory when "." is passed.

func (*FileSystem) Remove added in v0.2.0

func (f *FileSystem) Remove(name string) error

Remove deletes a file from the FTP server. Note: some server may return an error type even if delete is successful.

func (*FileSystem) RemoveAll added in v0.2.0

func (f *FileSystem) RemoveAll(name string) error

RemoveAll removes a directory and its contents recursively from the FTP server.

func (*FileSystem) Rename added in v0.2.0

func (f *FileSystem) Rename(oldname, newname string) error

Rename renames a file/directory on the FTP server.

func (*FileSystem) Stat added in v0.2.0

func (f *FileSystem) Stat(name string) (file_interface.FileInfo, error)

Stat returns information of the files/directories in the specified directory.

func (*FileSystem) UseLogger added in v0.2.0

func (f *FileSystem) UseLogger(logger interface{})

UseLogger sets the Logger interface for the FTP file system.

func (*FileSystem) UseMetrics added in v0.2.0

func (f *FileSystem) UseMetrics(metrics interface{})

UseMetrics sets the Metrics interface.

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(pattern string, args ...interface{})
	Logf(pattern string, args ...interface{})
	Errorf(pattern string, args ...interface{})
}

Logger interface is used by ftp package to log information about query execution.

type Metrics

type Metrics interface {
	NewHistogram(name, desc string, buckets ...float64)
	RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
}

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...any)

Debug mocks base method.

func (*MockLogger) Debugf added in v0.2.0

func (m *MockLogger) Debugf(pattern string, args ...any)

Debugf mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(pattern string, args ...any)

Errorf mocks base method.

func (*MockLogger) Logf

func (m *MockLogger) Logf(pattern string, args ...any)

Logf mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(args ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Debugf added in v0.2.0

func (mr *MockLoggerMockRecorder) Debugf(pattern any, args ...any) *gomock.Call

Debugf indicates an expected call of Debugf.

func (*MockLoggerMockRecorder) Errorf

func (mr *MockLoggerMockRecorder) Errorf(pattern any, args ...any) *gomock.Call

Errorf indicates an expected call of Errorf.

func (*MockLoggerMockRecorder) Logf

func (mr *MockLoggerMockRecorder) Logf(pattern any, args ...any) *gomock.Call

Logf indicates an expected call of Logf.

type MockMetrics

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

MockMetrics is a mock of Metrics interface.

func NewMockMetrics

func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics

NewMockMetrics creates a new mock instance.

func (*MockMetrics) EXPECT

func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMetrics) NewHistogram

func (m *MockMetrics) NewHistogram(name, desc string, buckets ...float64)

NewHistogram mocks base method.

func (*MockMetrics) RecordHistogram

func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)

RecordHistogram mocks base method.

type MockMetricsMockRecorder

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

MockMetricsMockRecorder is the mock recorder for MockMetrics.

func (*MockMetricsMockRecorder) NewHistogram

func (mr *MockMetricsMockRecorder) NewHistogram(name, desc any, buckets ...any) *gomock.Call

NewHistogram indicates an expected call of NewHistogram.

func (*MockMetricsMockRecorder) RecordHistogram

func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call

RecordHistogram indicates an expected call of RecordHistogram.

type MockftpResponse

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

MockftpResponse is a mock of ftpResponse interface.

func NewMockftpResponse

func NewMockftpResponse(ctrl *gomock.Controller) *MockftpResponse

NewMockftpResponse creates a new mock instance.

func (*MockftpResponse) Close

func (m *MockftpResponse) Close() error

Close mocks base method.

func (*MockftpResponse) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockftpResponse) Read

func (m *MockftpResponse) Read(buf []byte) (int, error)

Read mocks base method.

func (*MockftpResponse) SetDeadline

func (m *MockftpResponse) SetDeadline(t time.Time) error

SetDeadline mocks base method.

type MockftpResponseMockRecorder

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

MockftpResponseMockRecorder is the mock recorder for MockftpResponse.

func (*MockftpResponseMockRecorder) Close

Close indicates an expected call of Close.

func (*MockftpResponseMockRecorder) Read

func (mr *MockftpResponseMockRecorder) Read(buf any) *gomock.Call

Read indicates an expected call of Read.

func (*MockftpResponseMockRecorder) SetDeadline

func (mr *MockftpResponseMockRecorder) SetDeadline(t any) *gomock.Call

SetDeadline indicates an expected call of SetDeadline.

type MockserverConn

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

MockserverConn is a mock of serverConn interface.

func NewMockserverConn

func NewMockserverConn(ctrl *gomock.Controller) *MockserverConn

NewMockserverConn creates a new mock instance.

func (*MockserverConn) ChangeDir

func (m *MockserverConn) ChangeDir(path string) error

ChangeDir mocks base method.

func (*MockserverConn) CurrentDir

func (m *MockserverConn) CurrentDir() (string, error)

CurrentDir mocks base method.

func (*MockserverConn) Delete

func (m *MockserverConn) Delete(arg0 string) error

Delete mocks base method.

func (*MockserverConn) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockserverConn) FileSize

func (m *MockserverConn) FileSize(name string) (int64, error)

FileSize mocks base method.

func (*MockserverConn) GetTime

func (m *MockserverConn) GetTime(path string) (time.Time, error)

GetTime mocks base method.

func (*MockserverConn) List

func (m *MockserverConn) List(arg0 string) ([]*ftp.Entry, error)

List mocks base method.

func (*MockserverConn) Login

func (m *MockserverConn) Login(arg0, arg1 string) error

Login mocks base method.

func (*MockserverConn) MakeDir

func (m *MockserverConn) MakeDir(path string) error

MakeDir mocks base method.

func (*MockserverConn) Quit

func (m *MockserverConn) Quit() error

Quit mocks base method.

func (*MockserverConn) RemoveDir

func (m *MockserverConn) RemoveDir(path string) error

RemoveDir mocks base method.

func (*MockserverConn) RemoveDirRecur

func (m *MockserverConn) RemoveDirRecur(path string) error

RemoveDirRecur mocks base method.

func (*MockserverConn) Rename

func (m *MockserverConn) Rename(arg0, arg1 string) error

Rename mocks base method.

func (*MockserverConn) Retr

func (m *MockserverConn) Retr(arg0 string) (ftpResponse, error)

Retr mocks base method.

func (*MockserverConn) RetrFrom

func (m *MockserverConn) RetrFrom(arg0 string, arg1 uint64) (ftpResponse, error)

RetrFrom mocks base method.

func (*MockserverConn) Stor

func (m *MockserverConn) Stor(arg0 string, arg1 io.Reader) error

Stor mocks base method.

func (*MockserverConn) StorFrom

func (m *MockserverConn) StorFrom(arg0 string, arg1 io.Reader, arg2 uint64) error

StorFrom mocks base method.

type MockserverConnMockRecorder

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

MockserverConnMockRecorder is the mock recorder for MockserverConn.

func (*MockserverConnMockRecorder) ChangeDir

func (mr *MockserverConnMockRecorder) ChangeDir(path any) *gomock.Call

ChangeDir indicates an expected call of ChangeDir.

func (*MockserverConnMockRecorder) CurrentDir

func (mr *MockserverConnMockRecorder) CurrentDir() *gomock.Call

CurrentDir indicates an expected call of CurrentDir.

func (*MockserverConnMockRecorder) Delete

func (mr *MockserverConnMockRecorder) Delete(arg0 any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockserverConnMockRecorder) FileSize

func (mr *MockserverConnMockRecorder) FileSize(name any) *gomock.Call

FileSize indicates an expected call of FileSize.

func (*MockserverConnMockRecorder) GetTime

func (mr *MockserverConnMockRecorder) GetTime(path any) *gomock.Call

GetTime indicates an expected call of GetTime.

func (*MockserverConnMockRecorder) List

func (mr *MockserverConnMockRecorder) List(arg0 any) *gomock.Call

List indicates an expected call of List.

func (*MockserverConnMockRecorder) Login

func (mr *MockserverConnMockRecorder) Login(arg0, arg1 any) *gomock.Call

Login indicates an expected call of Login.

func (*MockserverConnMockRecorder) MakeDir

func (mr *MockserverConnMockRecorder) MakeDir(path any) *gomock.Call

MakeDir indicates an expected call of MakeDir.

func (*MockserverConnMockRecorder) Quit

Quit indicates an expected call of Quit.

func (*MockserverConnMockRecorder) RemoveDir

func (mr *MockserverConnMockRecorder) RemoveDir(path any) *gomock.Call

RemoveDir indicates an expected call of RemoveDir.

func (*MockserverConnMockRecorder) RemoveDirRecur

func (mr *MockserverConnMockRecorder) RemoveDirRecur(path any) *gomock.Call

RemoveDirRecur indicates an expected call of RemoveDirRecur.

func (*MockserverConnMockRecorder) Rename

func (mr *MockserverConnMockRecorder) Rename(arg0, arg1 any) *gomock.Call

Rename indicates an expected call of Rename.

func (*MockserverConnMockRecorder) Retr

func (mr *MockserverConnMockRecorder) Retr(arg0 any) *gomock.Call

Retr indicates an expected call of Retr.

func (*MockserverConnMockRecorder) RetrFrom

func (mr *MockserverConnMockRecorder) RetrFrom(arg0, arg1 any) *gomock.Call

RetrFrom indicates an expected call of RetrFrom.

func (*MockserverConnMockRecorder) Stor

func (mr *MockserverConnMockRecorder) Stor(arg0, arg1 any) *gomock.Call

Stor indicates an expected call of Stor.

func (*MockserverConnMockRecorder) StorFrom

func (mr *MockserverConnMockRecorder) StorFrom(arg0, arg1, arg2 any) *gomock.Call

StorFrom indicates an expected call of StorFrom.

Jump to

Keyboard shortcuts

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