zdpgo_ftp

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 12 Imported by: 0

README

zdpgo_ftp

FTP服务,FTP文件上传和下载

版本历史

  • v0.1.0 2022/05/30 新增:FTP服务,文件上传下载
  • v0.1.1 2022/06/07 新增:上传文件并检查MD5
  • v0.1.2 2022/06/26 升级:日志组件升级

使用示例

开启FTP服务

package main

import (
	"github.com/zhangdapeng520/zdpgo_ftp"
	"github.com/zhangdapeng520/zdpgo_log"
)

func main() {
	f := zdpgo_ftp.NewWithConfig(&zdpgo_ftp.Config{
		Debug:    true,
		Host:     "localhost",
		Port:     2122,
		Username: "admin",
		Password: "admin",
	}, zdpgo_log.Tmp)
	s := f.GetServer()
	err := s.Run()
	if err != nil {
		panic(err)
	}
}

使用FTP客户端上传

package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_ftp"
	"github.com/zhangdapeng520/zdpgo_log"
)

/*
@Time : 2022/6/7 11:53
@Author : 张大鹏
@File : main.go
@Software: Goland2021.3.1
@Description:
*/

func main() {
	f := zdpgo_ftp.NewWithConfig(&zdpgo_ftp.Config{
		Debug:    true,
		Host:     "localhost",
		Port:     2122,
		Username: "admin",
		Password: "admin",
	}, zdpgo_log.Tmp)
	client, err := f.GetClient()
	if err != nil {
		panic(err)
	}

	err = client.Upload("README.md", "README.md")
	err = client.Download("README.md", "README1.md")

	toBytes, err := client.DownloadToBytes("README.md")
	fmt.Println(string(toBytes))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn *ftp.ServerConn
	Log  *zdpgo_log.Log
}

func (*Client) ChangeDir

func (c *Client) ChangeDir(dirPath string) error

ChangeDir 切换工作目录

func (*Client) Close

func (c *Client) Close() error

Close 关闭客户端

func (*Client) CurrentDir

func (c *Client) CurrentDir() (string, error)

CurrentDir 获取当前目录

func (*Client) Download

func (c *Client) Download(srcPath, destPath string) error

Download 下载文件

func (*Client) DownloadToBytes

func (c *Client) DownloadToBytes(filePath string) ([]byte, error)

DownloadToBytes 下载文件并转换我bytes数组

func (*Client) GetMd5 added in v0.1.1

func (c *Client) GetMd5(data []byte) string

GetMd5 获取数据的MD5值

func (*Client) MakeDir

func (c *Client) MakeDir(dirPath string) error

MakeDir 创建目录

func (*Client) Retr

func (c *Client) Retr(filePath string) ([]byte, error)

Retr 获取文件内容

func (*Client) Store

func (c *Client) Store(fileName string, fileContent io.Reader) error

Store 存储文件

func (*Client) Upload

func (c *Client) Upload(srcPath, destPath string) error

Upload 上传文件

func (*Client) UploadAndCheckMd5

func (c *Client) UploadAndCheckMd5(srcPath, destPath string) bool

UploadAndCheckMd5 上传文件并校验MD5值

type Config

type Config struct {
	Debug       bool   `yaml:"debug" json:"debug"`
	LogFilePath string `yaml:"log_file_path" json:"log_file_path"`
	WorkDir     string `yaml:"root_dir" json:"root_dir"`
	Host        string `yaml:"host" json:"host"`
	Port        int    `yaml:"port" json:"port"`
	Username    string `yaml:"username" json:"username"`
	Password    string `yaml:"password" json:"password"`
}

type Ftp

type Ftp struct {
	Config *Config
	Log    *zdpgo_log.Log
}

func New

func New(log *zdpgo_log.Log) *Ftp

func NewWithConfig

func NewWithConfig(config *Config, log *zdpgo_log.Log) *Ftp

func (*Ftp) GetClient

func (f *Ftp) GetClient() (*Client, error)

GetClient 获取客户端

func (*Ftp) GetMd5 added in v0.1.1

func (f *Ftp) GetMd5(data []byte) string

GetMd5 获取数据的MD5值

func (*Ftp) GetServer

func (f *Ftp) GetServer() *Server

GetServer 获取服务端对象

func (*Ftp) IsHealth

func (f *Ftp) IsHealth() bool

type Server

type Server struct {
	Config *Config
	Log    *zdpgo_log.Log
}

func (*Server) Run

func (s *Server) Run() error

Run 运行服务

Directories

Path Synopsis
Package errwrap implements methods to formalize error wrapping in Go.
Package errwrap implements methods to formalize error wrapping in Go.
examples
client command
server command
Package ftp implements a FTP client as described in RFC 959.
Package ftp implements a FTP client as described in RFC 959.
pkg/credentials
Package credentials provides credential retrieval and management for S3 compatible object storage.
Package credentials provides credential retrieval and management for S3 compatible object storage.

Jump to

Keyboard shortcuts

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