sftps

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 17 Imported by: 0

README

SFTPS

sftps is an Package of the Golang for the FTP, FTPS and SFTP Clients.

Example

###1 Import the package "github.com/kooohei/sftps"

import (
  "github.com/kooohei/sftps"
)

###2 Create the parameters.

/*
  FTP, FTPS
*/
param := sftps.NewFtpParameters("[host]", [port], "[username]", "[password]", [bool for the Connection Keepalive])
// param.ActiveMode(123456)
// param.Secure(true)
// param.Implicit(990)
/*
  SFTP
*/
param := sftps.NewSftpParameters("[host]", [port], "[username]", "[password]", [bool for the Connection Keepalive])
// param.Keys("[path to the private key]", [bool for the use passphrase to the Key], "[passphrase]")

###3 Create the Receiver

/* FTP, FTPS */
var ftp *sftps.Ftp
var err error
if ftp, err = sftps.New(sftps.FTP, param); err != nil {
  panic(err)
}
// defer ftp.Quit() /* this line should be uncomment if specified true value to the keepalive */
/* SFTP */
var sftp *sftps.SecureFtp
var err error
if sftp, err = sftps.New(sftps.SFTP, param); err != nil {
  panic(err)
}

###4 Connect to Server

/* FTP, FTPS */
var res []*sftps.FtpResponse
var err error

if res, err = ftp.Connect(); err != nil {
  return
}

The FtpResponse contains The Executed Command String, Ftp Response Code and Response Message, Note that: The "res" is not necessarily nil if the "err" is not nil.

/* SFTP */
if err := sftp.Connect(); err != nil {
  return
}

###5 Execute Commands

Get the File List
/* FTP, FTPS */
var res []*sftps.FtpResponse
var err error

if res, list, err = ftp.List("."); err != nil {
  return
}
/* SFTP */
if list, err = sftp.List("."); err != nil {
  return
}
Useful function StringToEntities
if ents, err := ftp.StringToEntities(list); err != nil {
// if ents, err := sftp.StringToEntities(list); err =! nil {
  return
}
/*
  The ents is the Slice of a *Entity
  that contains information of the file.
*/
Create Directory
/* FTP, FTPS */
if res, err =  ftp.Mkdir("testDir"); err != nil {
  return
}
/* SFTP */
if err =  sftp.Mkdir("testDir"); err != nil {
  return
}
Remove Directory
/* FTP, FTPS */
if res, err = ftp.Rmdir("testDir"); err != nil {
  return
}
/* SFTP */
if err = ftp.Rmdir("testDir"); err != nil {
  return
}
Rename file or directory
/* FTP, FTPS */
if res, err = ftp.Rmdir("testDir"); err != nil {
  return
}
/* SFTP */
if err = sftp.Rmdir("testDir"); err != nil {
  return
}
Upload File
/* FTP, FTPS */
if res, len, err = ftp.Upload("./upload.txt", "remote.txt") err != nil {
  return
}
/* SFTP */
if len, err = sftp.Upload("./upload.txt", "remote.txt") err != nil {
  return
}
Download File
/* FTP, FTPS */
if res, len, err = ftp.Download("./downloaded.txt", "remote.txt"); err != nil {
  return
}
/* SFTP */
if len, err = ftp.Download("./downloaded.txt", "remote.txt"); err != nil {
  return
}

other functions will be ready soon.

Documentation

Index

Constants

View Source
const (
	ONLINE  int = 1
	OFFLINE int = 2
)
View Source
const (
	FTP  int = 1
	FTPS int = 2
	SFTP int = 3
)
View Source
const (
	DOWNLOAD int = 1
	UPLOAD   int = 2
)
View Source
const (
	IMPLICIT int = 1
	EXPLICIT int = 2
)
View Source
const (
	// When handshake to the server
	TIMEOUT string = "10s"
	// The Keep Alive Period for an active network connection.
	KEEPALIVE string = "30s"
)
View Source
const (
	NONE int = 0
)

Variables

This section is empty.

Functions

func NewFtpParameters

func NewFtpParameters(host string, port int, user string, pass string, keepalive bool) *ftpParameters

func NewSftpParameters

func NewSftpParameters(host string, port int, user string, pass string, keepAlive bool) *sftpParameters

Types

type Entity

type Entity struct {
	Perms   *Permissions
	Links   int
	Owner   string
	Group   string
	Size    int
	LastMod string
	Name    string
}

type Ftp

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

func (*Ftp) Command

func (this *Ftp) Command(cmd string, code int) (res *FtpResponse, err error)

type FtpResponse

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

type Permission

type Permission struct {
	Read  bool
	Write bool
	Exe   bool
}

type Permissions

type Permissions struct {
	Type   string
	Sticky bool
	SUID   bool
	SGID   bool
	Owner  *Permission
	Group  *Permission
	Users  *Permission
}

type SecureFtp

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

type Sftps

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

func New

func New(proto int, param interface{}) (sftps *Sftps, err error)

func (*Sftps) Connect

func (this *Sftps) Connect() (res []*FtpResponse, err error)

func (*Sftps) Download

func (this *Sftps) Download(local string, remote string) (res []*FtpResponse, len int64, err error)

func (*Sftps) List

func (this *Sftps) List(baseDir string) (res []*FtpResponse, list string, err error)

func (*Sftps) Mkdir

func (this *Sftps) Mkdir(p string) (res []*FtpResponse, err error)

func (*Sftps) Quit

func (this *Sftps) Quit() (res *FtpResponse, err error)

func (*Sftps) Rename

func (this *Sftps) Rename(old string, new string) (res []*FtpResponse, err error)

func (*Sftps) Rmdir

func (this *Sftps) Rmdir(p string) (res []*FtpResponse, err error)

func (*Sftps) StringToEntities

func (this *Sftps) StringToEntities(raw string) (ents []*Entity, err error)

func (*Sftps) Upload

func (this *Sftps) Upload(local string, remote string) (res []*FtpResponse, len int64, err error)

*

parameter's explain. local is the local path for the file, whether remote.

Jump to

Keyboard shortcuts

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