在Golang中实现github.com/jlaffaye/ftp。

huangapple go评论90阅读模式
英文:

implement github.com/jlaffaye/ftp in golang

问题

我是新手,正在尝试使用golang实现一个FTP客户端来从服务器获取文件。
我尝试了几个包,比如:"github.com/dutchcoders/goftp",但是walk支持没有起作用。
我目前正在尝试使用"github.com/jlaffaye/ftp",但是无法连接到服务器。

我导入了这个包,并且简单地使用以下代码进行连接:

func main() {
    ftp, err := Connect(address:port)
    ftp.Login("user", "password")
    if ftp.Code == 530 {
        log.Println("Failed to Login")
    }
    log.Println("Successfully Connected to", ftp)
}

当我运行时,它显示undefined: Connect。

我正在按照该包的godocs进行操作。

GODOC链接:https://godoc.org/github.com/jlaffaye/ftp

英文:

I am new to golang I'm trying to implement an FTP client to get files from a server.
I tried several packages like :"github.com/dutchcoders/goftp" but walk support was not working.
Im currently trying with "github.com/jlaffaye/ftp" but cant seem to connect to the server.

I imported the package and Im simply using the following code to connect:

func main(){

ftp,err := Connect(address:port)

ftp.Login("user", "password")
if ftp.Code == 530 {
    log.Println("Failed to Login")
}


log.Println("Successfully Connected to",  ftp)

}

when i run it gives undefined: Connect

I am following the godocs for this package

GODOC: https://godoc.org/github.com/jlaffaye/ftp

答案1

得分: 2

你必须在函数前面加上函数所在的包名。

在你的例子中,Connect是来自ftp包的,你应该写成ftp.Connect

不要忘记导入包:

在文件开头加上:

import github.com/jlaffaye/ftp
英文:

You have to precede a function with the package from where this function is.

In your example Connect is from ftp package, you should write ftp.Connect instead.

Do not forget to import the package :

import github.com/jlaffaye/ftp

at the beginning of the file.

huangapple
  • 本文由 发表于 2016年11月18日 20:47:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/40677539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定