goftp

package module
v0.0.0-...-436f60b Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2017 License: LGPL-3.0 Imports: 8 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

goftp

Build Status GoDoc Go Report Card codecov

Goftp is a simple FTP library written in golang. The implementation is based on the RFC 959 - FILE TRANSFER PROTOCOL (FTP)

Features

  • active and passive data connection mode

Usage

Download the package and import it into your project.

import ftp "github.com/martinr92/goftp"

Connect to the remote server.

ftpClient, err := ftp.NewFtp("host.local:51000")
if err != nil {
    panic(err)
}
defer ftpClient.Close()

By default, the client uses a passive data connection for file transfer. If you want to use a active connection, just set the following:

ftpClient.ActiveMode = true
ftpClient.ActiveModeIPv4 = "1.2.3.4"

Send user credentials.

if err = ftpClient.Login("username", "password"); err != nil {
    panic(err)
}

Change the working directory.

if err = ftpClient.OpenDirectory("/some/folder/"); err != nil {
    panic(err)
}

Upload a file.

if err = ftpClient.Upload("/local/path/file.txt", "file.txt"); err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ftp

type Ftp struct {
	ActiveMode     bool
	ActiveModeIPv4 string
	Verbose        bool
	// contains filtered or unexported fields
}

Ftp object for remote connection.

func NewFtp

func NewFtp(remote string) (*Ftp, error)

NewFtp creates a new FTP connection object.

Examples:

NewFtp("my.host.de:1234")

func (*Ftp) Close

func (ftp *Ftp) Close()

Close quits the connection.

func (*Ftp) CreateDirectory

func (ftp *Ftp) CreateDirectory(directory string) error

CreateDirectory tells the server, to create a new named directory.

func (*Ftp) Login

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

Login sends credentials to the FTP server and verifies the server login response status.

func (*Ftp) OpenDirectory

func (ftp *Ftp) OpenDirectory(directory string) error

OpenDirectory changes the current working directory.

func (*Ftp) Upload

func (ftp *Ftp) Upload(localFilePath string, remoteFilePath string) error

Upload a file to the remote server. Make shure, that the correct directory is already open! You can use OpenDirectory to change in the directory you want to use.

type FtpError

type FtpError struct {
	ExpectedStatusCodes []FtpStatus
	ServerResponse      string
}

FtpError is a custom error struct for FTP communication errors.

func (*FtpError) Error

func (ftpError *FtpError) Error() string

type FtpStatus

type FtpStatus int

FtpStatus status codes by RFC 959 https://tools.ietf.org/html/rfc959

const (
	// FtpStatusFileOK - File status okay; about to open data connection.
	FtpStatusFileOK FtpStatus = 150

	// FtpStatusCommandOK - Command okay.
	FtpStatusCommandOK FtpStatus = 200

	// FtpStatusReadyForNewUser - Service ready for new user.
	FtpStatusReadyForNewUser FtpStatus = 220

	// FtpStatusClosingDataConnection - Closing data connection.
	FtpStatusClosingDataConnection FtpStatus = 226

	// FtpStatusEnteringPassiveMode - Entering Passive Mode (h1,h2,h3,h4,p1,p2).
	FtpStatusEnteringPassiveMode FtpStatus = 227

	// FtpStatusLoginOK - User logged in, proceed.
	FtpStatusLoginOK FtpStatus = 230

	// FtpStatusFileActionOK - Requested file action okay, completed.
	FtpStatusFileActionOK FtpStatus = 250

	// FtpStatusPathCreated - Path created.
	FtpStatusPathCreated FtpStatus = 257

	// FtpStatusUserNameOK - User name okay, need password.
	FtpStatusUserNameOK FtpStatus = 331

	// FtpStatusLoginIncorrect - Not logged in.
	FtpStatusLoginIncorrect FtpStatus = 530

	// FtpStatusRequestedActionNotTaken - Requested action not taken.
	// File unavailable (e.g., file not found, no access).
	FtpStatusRequestedActionNotTaken FtpStatus = 550
)

Jump to

Keyboard shortcuts

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