ftpsclient

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

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

Go to latest
Published: Nov 1, 2014 License: Apache-2.0 Imports: 12 Imported by: 0

README

FTPS client for Go(lang)

Another Ftp client package for the go language with secure support.

Package FtpsClient implements a basic ftp(s) client which can be used to connect
an application to a ftp server. Only a small subset of the full FTP/FTPS specification
is supported

It is based on the work made by:
- jlaffaye 			github.com/jlaffaye/ftp
- smallfish 		github.com/smallfish/ftp
- Marco Beierer 	github.com/webguerilla/ftps

And has some other feature such as:
- Refactored with onbings coding covention
- Add secure/unsecure mode
- Add timeout support
- Add rx and tx buffer sizing support
- Add generic Ftp control send command function (SendFtpCtrlCommand) to be able to send SITE, 
  NOOP,... ftp command)
- Fix a number of problems in LIST command parsing

INSTALL

go get github.com/onbings/ftpsclient

EXAMPLE

package main

import (          
	"fmt"
	"log"
	"github.com/onbings/ftpsclient"
)

func main() {

	var FtpsClientParam_X ftpsclient.FtpsClientParam

	FtpsClientParam_X.Id_U32 = 123
	FtpsClientParam_X.LoginName_S = "mc"
	FtpsClientParam_X.LoginPassword_S = "a"
	FtpsClientParam_X.InitialDirectory_S = "/Seq"
	FtpsClientParam_X.SecureFtp_B = false
	FtpsClientParam_X.TargetHost_S = "127.0.0.1"
	FtpsClientParam_X.TargetPort_U16 = 21
	FtpsClientParam_X.Debug_B = false
	FtpsClientParam_X.TlsConfig_X.InsecureSkipVerify = true
	FtpsClientParam_X.ConnectTimeout_S64 = 2000
	FtpsClientParam_X.CtrlTimeout_S64 = 1000
	FtpsClientParam_X.DataTimeout_S64 = 5000
	FtpsClientParam_X.CtrlReadBufferSize_U32 = 0
	FtpsClientParam_X.CtrlWriteBufferSize_U32 = 0
	FtpsClientParam_X.DataReadBufferSize_U32 = 0x100000
	FtpsClientParam_X.DataWriteBufferSize_U32 = 0x100000

	FtpsClientPtr_X := ftpsclient.NewFtpsClient(&FtpsClientParam_X)
	if FtpsClientPtr_X != nil {
		Err := FtpsClientPtr_X.Connect()
		if Err == nil {
			DirEntryArray_X, Err := FtpsClientPtr_X.List()
			if Err == nil {
				for _, DirEntry_X := range DirEntryArray_X {
					fmt.Printf("(%d): %s.%s %d bytes %s\n", DirEntry_X.Type_E, DirEntry_X.Name_S, DirEntry_X.Ext_S, DirEntry_X.Size_U64, DirEntry_X.Time_X)
				}
				ReplyCode_i, ReplyMessage_S, Err := FtpsClientPtr_X.SendFtpCtrlCommand("FEAT", 211)
				fmt.Printf("feat %d %s\n", ReplyCode_i, ReplyMessage_S)
				Err = FtpsClientPtr_X.Disconnect()
			}
		}
	}
}

Documentation

Overview

Package FtpsClient implements a basic ftp(s) client which can be used to connect an application to a ftp server. Only a small subset of the full FTP/FTPS specification is supported

It is based on the word made by: - jlaffaye github.com/jlaffaye/ftp - smallfish github.com/smallfish/ftp - Marco Beierer github.com/webguerilla/ftps

And has some other feature such as: - Refactored with onbings coding covention - Add secure/unsecure mode - Add timeout support - Add generic Ftp control send command function (SendFtpCommand) to be able to send SITE, NOOP,... ftp command) - Fix problems in the 'LIST' result command parsing

Usage

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParameter = errors.New("Ftps: Invalid parameter")
	ErrNotConnected     = errors.New("Ftps: Connection is not established")
	ErrPasv             = errors.New("Ftps: Invalid PASV response format")
	ErrIoError          = errors.New("Ftps: File transfer not complete")
	ErrLineFormat       = errors.New("Ftps: Unsupported line format")
	ErrDirEntry         = errors.New("Ftps: Unknown directory entry type")
	ErrInvalidLogin     = errors.New("Ftps: Invalid loging")
	ErrInvalidDirectory = errors.New("Ftps: Invalid directory")
	ErrNotDisconnected  = errors.New("Ftps: Can't disconnect")
	ErrSecure           = errors.New("Ftps: Secure protocol error")
)

Error messages generated by this package

Functions

This section is empty.

Types

type ConBufferSetter

type ConBufferSetter interface {
	SetReadBuffer(bytes int) error
	SetWriteBuffer(bytes int) error
}

Interface used to fiw tx and rx buffer size

type DIRENTRYTYPE

type DIRENTRYTYPE int

File type container

const (
	DIRENTRYTYPE_FILE DIRENTRYTYPE = iota
	DIRENTRYTYPE_FOLDER
	DIRENTRYTYPE_LINK
)

File type in a directory

type DirEntry

type DirEntry struct {
	Type_E   DIRENTRYTYPE
	Name_S   string
	Ext_S    string
	Size_U64 uint64
	Time_X   time.Time
}

File characteristics

type FtpsClient

type FtpsClient struct {
	FtpsParam_X FtpsClientParam
	// contains filtered or unexported fields
}

Ftps characteristics

func NewFtpsClient

func NewFtpsClient(_FtpsClientParamPtr_X *FtpsClientParam) *FtpsClient

Create a new FtpsClient based on the parameters stored in _FtpsClientParamPtr_X. Returns pointer to FtpsClient

func (*FtpsClient) ChangeWorkingDirectory

func (this *FtpsClient) ChangeWorkingDirectory(_Path_S string) (rRts error)

Change the current working ftp directory Returns error object

func (*FtpsClient) CloseFtpDataChannel

func (this *FtpsClient) CloseFtpDataChannel() (rReplyCode_i int, rReplyMessage_S string, rRts error)

Close ftp data channel Returns error code, reply message and error object

func (*FtpsClient) Connect

func (this *FtpsClient) Connect() (rRts error)

Connect the client application to the remote ftp server Returns error object

func (*FtpsClient) DeleteFile

func (this *FtpsClient) DeleteFile(_Path_S string) (rRts error)

Delete a file called '_Path_S' on the remote Ftp server Returns error object

func (*FtpsClient) Disconnect

func (this *FtpsClient) Disconnect() (rRts error)

Disconnect from remote ftp server Returns error object

func (*FtpsClient) GetWorkingDirectory

func (this *FtpsClient) GetWorkingDirectory() (rDirectory_S string, rRts error)

Returns the current working ftp directory Returns current working ftp directory and error object

func (*FtpsClient) List

func (this *FtpsClient) List() (rDirEntryArray_X []DirEntry, rRts error)

Execute the Ftp 'LIST' command Returns the list of file object present on the ftp server and error object

func (*FtpsClient) MakeDirectory

func (this *FtpsClient) MakeDirectory(_Path_S string) (rRts error)

Create a directory called '_Path_S' on the remote Ftp server Returns error object

func (*FtpsClient) OpenFtpDataChannel

func (this *FtpsClient) OpenFtpDataChannel(_FtpCommand_S string, _ExpectedReplyCode_i int) (rReplyCode_i int, rReplyMessage_S string, rRts error)

Open ftp data channel based on '_FtpCommand_S' command and wait for ftp answer. Success when '_ExpectedReplyCode_i' is detected Returns error code, reply message and error object

func (*FtpsClient) ReadFtpDataChannel

func (this *FtpsClient) ReadFtpDataChannel(_ExitAfterFirstRead_B bool, _DataArray_U8 []uint8) (rWaitDuration_S64 time.Duration, rIoDuration_S64 time.Duration, rNbRead_i int, rRts error)

Read data stream from ftp data channel Returns wait and io duration, number of byte read and error object

func (*FtpsClient) RemoveDirectory

func (this *FtpsClient) RemoveDirectory(_Path_S string) (rRts error)

Delete a directory called '_Path_S' on the remote Ftp server Returns error object

func (*FtpsClient) RetrieveFile

func (this *FtpsClient) RetrieveFile(_RemoteFilepath_S, _LocalFilepath_S string) (rRts error)

Read the file called '_RemoteFilepath_S' on the ftp remote ftp server and store its contents in local file '_RemoteFilepath_S' Returns error object

func (*FtpsClient) SendFtpCtrlCommand

func (this *FtpsClient) SendFtpCtrlCommand(_FtpCommand_S string, _ExpectedReplyCode_i int) (rReplyCode_i int, rReplyMessage_S string, rRts error)

Send a ftp command '_FtpCommand_S' and wait for ftp answer. Success when '_ExpectedReplyCode_i' is detected. Returns error code, reply message and error object

func (*FtpsClient) StoreFile

func (this *FtpsClient) StoreFile(_RemoteFilepath_S string, _DataArray_U8 []byte) (rRts error)

Store the '_DataArray_U8' as a file called '_RemoteFilepath_S' on the ftp remote ftp server Returns error object

type FtpsClientParam

type FtpsClientParam struct {
	//public
	Id_U32                  uint32
	LoginName_S             string
	LoginPassword_S         string
	InitialDirectory_S      string
	SecureFtp_B             bool
	TargetHost_S            string
	TargetPort_U16          uint16
	Debug_B                 bool
	TlsConfig_X             tls.Config
	ConnectTimeout_S64      time.Duration
	CtrlTimeout_S64         time.Duration
	DataTimeout_S64         time.Duration
	CtrlReadBufferSize_U32  uint32
	CtrlWriteBufferSize_U32 uint32
	DataReadBufferSize_U32  uint32
	DataWriteBufferSize_U32 uint32
}

Ftps client working parameters

Jump to

Keyboard shortcuts

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