golang ftp客户端示例 支持断点续传

前端之家收集整理的这篇文章主要介绍了golang ftp客户端示例 支持断点续传前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 @R_502_159@")
        os.Exit(1)
    }
    defer ftpClient.Quit()

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

    //Print the current working directory
    var cwd string
    cwd,err = ftpClient.Pwd()
    if err != nil {
        fmt.Println("The Pwd command @R_502_159@")
        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 @R_502_159@")
        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)
    }

}
原文链接:https://www.f2er.com/go/190132.html

猜你在找的Go相关文章