// Package cftp provides functionality. package cftp import ( "bufio" "errors" "net" "strings" "time" "rocketgit.ru/rsmon/worker/app/models" ) const stateERR = "ERR" // Perform provides functionality. func Perform(c *models.Check) *Result { result := &Result{} host := c.GetSettings().Port if host == "" { host = "21" } result.State = "START" client := &net.Dialer{ Timeout: 10 * time.Second, DualStack: true, } start := time.Now() conn, err := client.Dial("tcp", net.JoinHostPort(c.Monitor.Host, host)) if err != nil { result.State = stateERR result.Error = err result.Duration = time.Since(start) return result } result.Duration = time.Since(start) status, err := bufio.NewReader(conn).ReadString('\n') if err != nil { result.State = stateERR result.Error = err return result } if strings.Contains(status, "FTP") { result.State = "OK" } else { result.State = stateERR result.Error = errors.New("it's not FTP") } return result }