My solution is add log file to ncftpput
package ncftp
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
type NcFtpPut struct {
logdir string
loginCfg string
remotPath string
localPath string
debugFile string
}
func NewNcFtpPut(logdir, loginCfg, remotPath, localPath string) *NcFtpPut {
return &NcFtpPut{
logdir: logdir,
loginCfg: loginCfg,
remotPath: remotPath,
localPath: localPath,
}
}
func (n *NcFtpPut) Run() error {
n.buildDebugFile()
args := n.buildArgs()
if err := n.execCmd(args[0], args[1:]...); err != nil {
return err
}
if err := n.analisysDebugFile(); err != nil {
return err
}
return nil
}
func (n *NcFtpPut) buildArgs() []string {
args := []string{"ncftpput", "-R"}
args = append(args, "-f")
args = append(args, n.loginCfg)
args = append(args, "-d")
args = append(args, n.debugFile)
args = append(args, n.remotPath)
args = append(args, n.localPath)
return args
}
func (n *NcFtpPut) buildDebugFile() {
n.debugFile = filepath.Join(n.logdir, "ftp.log")
os.Remove(n.debugFile)
}
func (n *NcFtpPut) execCmd(cmdName string, args ...string) error {
cmd := exec.Command(cmdName, args...)
stdOut, err := cmd.CombinedOutput()
errOut := hasOutput(stdOut)
if err != nil {
if errOut != nil {
return fmt.Errorf("%s:%s", err, errOut)
}
return err
}
if errOut != nil {
return errOut
}
return nil
}
func hasOutput(stdOut []byte) error {
if stdOut != nil {
return errors.New(string(stdOut))
}
return nil
}
func (n *NcFtpPut) analisysDebugFile() error {
buf, err := ioutil.ReadFile(n.debugFile)
if err != nil {
return err
}
ret := string(buf)
if strings.Contains(ret, "Operation successful") {
return nil
}
return errors.New("error pls read ftplog file")
}