Git Product home page Git Product logo

ftp4go's Introduction

This is an FTP client started as a port of the standard Python FTP client library
Forked form code.google.com/p/ftp4go and change some dependenes of the package

Installation

go get github.com/shenshouer/ftp4go

How to use it

Import the library in your code and call the methods exposed by the FTP structure, for instance:

package main  
import (
  "fmt"
  "os"
  ftp4go "github.com/shenshouer/ftp4go"
)  
func main() {
  ftpClient := ftp4go.NewFTP(0) // 1 for debugging
  //connect
  _, err := ftpClient.Connect("myFtpAddress", ftp4go.DefaultFtpPort)
  if err != nil {
    fmt.Println("The connection failed")
    os.Exit(1)
  }   
  defer ftpClient.Quit()
  _, err = ftpClient.Login("myUsername", "myPassword", "")
  if err != nil {
    fmt.Println("The login failed")
    os.Exit(1)
  }      
  //Print the current working directory
  var cwd string
  cwd, err = ftpClient.Pwd()
  if err != nil {
    fmt.Println("The Pwd command failed")
    os.Exit(1)
  }
  fmt.Println("The current folder is", cwd)
}

断点续传示例

package main

import (
	ftp4go "github.com/shenshouer/ftp4go"
	"fmt"
	"os"
)

var(
	downloadFileName 	= "DockerToolbox-1.8.2a.pkg"
	BASE_FTP_PATH 		= "/home/bob/"					// base data path in ftp server
)

func main() {
	ftpClient := ftp4go.NewFTP(0) // 1 for debugging

	//connect
	_, err := ftpClient.Connect("172.8.4.101", ftp4go.DefaultFtpPort, "")
	if err != nil {
		fmt.Println("The connection failed")
		os.Exit(1)
	}
	defer ftpClient.Quit()

	_, err = ftpClient.Login("bob", "p@ssw0rd", "")
	if err != nil {
		fmt.Println("The login failed")
		os.Exit(1)
	}

	//Print the current working directory
	var cwd string
	cwd, err = ftpClient.Pwd()
	if err != nil {
		fmt.Println("The Pwd command failed")
		os.Exit(1)
	}
	fmt.Println("The current folder is", cwd)


	// get the remote file size
	size, err := ftpClient.Size("/home/bob/"+downloadFileName)
	if err != nil {
		fmt.Println("The Pwd command failed")
		os.Exit(1)
	}
	fmt.Println("size ", size)

	// start resume file download
	if err = ftpClient.DownloadResumeFile("/home/bob/"+downloadFileName, "/Users/goyoo/ftptest/"+downloadFileName, false); err != nil{
		panic(err)
	}

}

More on the code

Being a port of a Python library, the original Python version is probably the best reference.
Python ftplib

Differences to the original version

Some new methods have been implemented to upload and download files, recursively in a folder as well.

TODOs and unsupported functionality

  • TLS is not supported yet
  • add multi goroutine for one download task support

ftp4go's People

Contributors

mezzato avatar shenshouer avatar bugs33ker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.