How to solve the error of the rsync error: error i

2019-08-26 20:36发布

问题:

I'm using a command of rsync for making a new directory to save the images the command is "rsync -ave --rsync-path='mkdir -p " + path + " && rsync' " + filePath + " ubuntu@" + LocalhostIp + ":" + path but while running my code this command will gives me the error the error is

Error:

exit status 14: rsync: Failed to exec --rsync-path=mkdir: No such file or directory (2)

rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.2]

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: error in IPC code (code 14) at io.c(235) [sender=3.1.2]

Edit

func CopyUploadedFileToAppServers(filePath, path string) {
   ExecuteCommand("rsync -ave --rsync-path='mkdir -p " + path + " && rsync' " + filePath + " ubuntu@" + LocalhostIp + ":" + path)
}

func ExecuteCommand(command string) error{
 cmd := exec.Command("sh", "-c",command)
 var out bytes.Buffer
 var stderr bytes.Buffer
 cmd.Stdout = &out
 cmd.Stderr = &stderr

 err := cmd.Run()

 if err != nil {
    fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
    return err
 }
 fmt.Println("Result: " + out.String())
 return nil
}

How can I solve this error?

回答1:

You need to remove the -e option, as this is taking the following work (--rsync-path=...) as the replacement for the ssh command. For example,

$ rsync -ave --x_x  /tmp/a abc@localhost:/tmp/y
rsync: Failed to exec --x_x: No such file or directory (2)

Just use -av.