英文:
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
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论