ftpgo

package module
v0.0.0-...-a3c2898 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2017 License: MIT Imports: 12 Imported by: 0

README

ftpgo

Build Status

FTP client for Golang. (respond to passive and active)

# assume the following codes in example.go file
$ cat example.go
package main

import "github.com/kzdev/ftpgo"

func main() {
	var err error
	var ftpConn *common.EkpsFtp

	addr := net.JoinHostPort("192.168.10.1", strconv.Itoa(21))
	if ftpConn, err = common.FtpConnect(addr, time.Duration(5)*time.Second); err != nil {
		fmt.Println(err.Error())
	}
	defer ftpConn.Quit()

	if err := ftpConn.Login("userid", "password"); err != nil {
		fmt.Println(err.Error())
		return
	}

	ftpConn.SetPasv(true)

	fileList, err := ftpConn.List("/home/kzdev")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	for _, file := range fileList {
		fmt.Println(file)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileMatchList

func FileMatchList(dir string, regexp string) (matches []string)

FileMatchList dir search

func ParseDateTime

func ParseDateTime(fields []string) (mtime time.Time, err error)

ParseDateTime parse date

func ParseDosDateTime

func ParseDosDateTime(input string) (dateTime time.Time, err error)

ParseDosDateTime file time parse for DOS

func ReadFileList

func ReadFileList(filename string) []string

ReadFileList get row data list

func Readln

func Readln(r *bufio.Reader) (string, error)

Readln readerから1行分の文字列を取得する

func SaveFile

func SaveFile(filename string, text []byte) error

SaveFile byte data save to file

Types

type Ftp

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

Ftp struct

func FtpConnect

func FtpConnect(addr string, timeout time.Duration) (*Ftp, error)

FtpConnect Connect to server

func (*Ftp) Abort

func (c *Ftp) Abort() error

Abort a file transfer that is in progress.

func (*Ftp) Cdup

func (c *Ftp) Cdup() error

Cdup issues a CDUP FTP command, which changes the current directory to the parent directory. This is similar to a call to ChangeDir with a path set to "..".

func (*Ftp) Cwd

func (c *Ftp) Cwd(path string) error

Cwd issues a CWD FTP command, which changes the current directory to the specified path.

func (*Ftp) Delete

func (c *Ftp) Delete(path string) error

Delete issues a DELE FTP command to delete the specified file from the remote FTP server.

func (*Ftp) Dir

func (c *Ftp) Dir(args ...string) (infos []*FtpFile, err error)

Dir issues a LIST FTP command.

func (*Ftp) List

func (c *Ftp) List(args ...string) (lines []string, err error)

List issues a LIST FTP command.

func (*Ftp) ListRequest

func (c *Ftp) ListRequest(args ...string) (io.ReadCloser, error)

ListRequest issues a LIST FTP command.

func (*Ftp) Login

func (c *Ftp) Login(user, password string) error

Login as the given user.

func (*Ftp) Mkd

func (c *Ftp) Mkd(path string) (string, error)

Mkd issues a MKD FTP command to create the specified directory on the remote FTP server.

func (*Ftp) Nlst

func (c *Ftp) Nlst(args ...string) (lines []string, err error)

Nlst issues an NLST FTP command.

func (*Ftp) NlstRequest

func (c *Ftp) NlstRequest(args ...string) (io.ReadCloser, error)

NlstRequest issues an NLST FTP command.

func (*Ftp) Noop

func (c *Ftp) Noop() error

Noop has no effects and is usually used to prevent the remote FTP server to close the otherwise idle connection.

func (*Ftp) Pasv

func (c *Ftp) Pasv() (host string, port int, err error)

Pasv issues a "PASV" command to get a port number for a data connection.

func (*Ftp) Port

func (c *Ftp) Port(host string, port int) error

Port issues a PORT FTP command

func (*Ftp) Pwd

func (c *Ftp) Pwd() (string, error)

Pwd issues a PWD FTP command, which Returns the path of the current directory.

func (*Ftp) Quit

func (c *Ftp) Quit() error

Quit issues a QUIT FTP command to properly close the connection from the remote FTP server.

func (*Ftp) ReadResponse

func (c *Ftp) ReadResponse(expectCode int, t time.Time) (int, string, error)

ReadResponse issues a FTP command response

func (*Ftp) Rein

func (c *Ftp) Rein() error

Rein issues a REIN FTP command to logout the current user. ftp server optional command.

func (*Ftp) Rename

func (c *Ftp) Rename(from, to string) error

Rename renames a file on the remote FTP server.

func (*Ftp) Rest

func (c *Ftp) Rest(offset uint64) error

Rest issues a REST FTP command.

func (*Ftp) Retr

func (c *Ftp) Retr(path string) error

Retr issues a RETR FTP command to fetch the specified file from the remote FTP server

func (*Ftp) RetrFile

func (c *Ftp) RetrFile(remote, local string) error

RetrFile issues a RETR FTP command to fetch the specified file from the remote FTP server

func (*Ftp) RetrRequest

func (c *Ftp) RetrRequest(path string) (io.ReadCloser, error)

RetrRequest issues a RETR FTP command to fetch the specified file from the remote FTP server The returned ReadCloser must be closed to cleanup the FTP data connection.

func (*Ftp) Rmd

func (c *Ftp) Rmd(path string) error

Rmd issues a RMD FTP command to remove the specified directory from the remote FTP server.

func (*Ftp) SendCmd

func (c *Ftp) SendCmd(expectCode int, format string, args ...interface{}) (int, string, error)

SendCmd Send a simple command string to the server and return the code and response string.

func (*Ftp) SetPasv

func (c *Ftp) SetPasv(ispassive bool)

SetPasv sets the mode to passive or active for data transfers.

func (*Ftp) Size

func (c *Ftp) Size(filename string) (int, error)

Size Request the size of the file named filename on the server. On success, the size of the file is returned as an integer. ftp server extension command.

func (*Ftp) Stor

func (c *Ftp) Stor(path string) error

Stor issues a STOR FTP command to store a file to the remote FTP server.

func (*Ftp) StorFile

func (c *Ftp) StorFile(local, remote string) error

StorFile issues a STOR FTP command to store a file to the remote FTP server.

func (*Ftp) StorRequest

func (c *Ftp) StorRequest(path string) (io.WriteCloser, error)

StorRequest issues a STOR FTP command to store a file to the remote FTP server. The returned WriteCloser must be closed to cleanup the FTP data connection.

func (*Ftp) Type

func (c *Ftp) Type(param string) error

Type issues a TYPE FTP command

type FtpDataConnector

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

FtpDataConnector data connection

func (*FtpDataConnector) Close

func (r *FtpDataConnector) Close() error

Close to data connection

func (*FtpDataConnector) Read

func (r *FtpDataConnector) Read(buf []byte) (int, error)

Read from data connection

func (*FtpDataConnector) Write

func (r *FtpDataConnector) Write(buf []byte) (int, error)

Write to data connection

type FtpFile

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

FtpFile struct

func NewFtpFile

func NewFtpFile(line string) (*FtpFile, error)

NewFtpFile construct

func ParseDosFormat

func ParseDosFormat(input string) (*FtpFile, error)

ParseDosFormat file time parse for DOS

func ParseUnixFormat

func ParseUnixFormat(input string) (*FtpFile, error)

ParseUnixFormat file time parse for UNIX

func (*FtpFile) IsDir

func (f *FtpFile) IsDir() bool

IsDir get dirpath

func (*FtpFile) ModTime

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

ModTime get updatetime of file

func (*FtpFile) Mode

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

Mode get filemode

func (*FtpFile) Name

func (f *FtpFile) Name() string

Name get filename

func (*FtpFile) Size

func (f *FtpFile) Size() int64

Size get filesize

func (*FtpFile) Sys

func (f *FtpFile) Sys() interface{}

Sys get sys

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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