A FTP and FTPS client package for Go
go get -u github.com/dchang-dchang/ftp
Create a FTP connection
host, port:="ftp.hostname.com", 21_=s.Dial(fmt.Sprintf("%s:%d", host, port))
defers.Quit()Set timeouts, debug mode, and/or TLS config for implicit TLS
(Note: If a TLSConfig is set, both the command and data channel will be secured with the same config)
host, port:="ftp.hostname.com", 990s:= ftp.ServerConn{
Debug: true,
Timeout: 30*time.Second,
TLSConfig: &tls.Config{ServerName: host},
}
_=s.Dial(fmt.Sprintf("%s:%d", host, port))
defers.Quit()Login
_=s.Login(username, password)List files
entries, _:=s.List("/")
for_, entry:=rangeentries {
fmt.Println(entry)
}Get a file
res, _:=s.Retr("/filename.txt")
reader:=bufio.NewReader(res)
for {
line, err:=reader.ReadString('\n')
iferr==io.EOF {
break
} elseiferr!=nil {
panic(err)
}
fmt.Println(line)
}