add rsh command

This commit is contained in:
Celogeek 2023-08-16 09:53:30 +02:00
parent c3813c0192
commit f38a80b9d3
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
2 changed files with 14 additions and 4 deletions

View File

@ -18,6 +18,7 @@ func main() {
flag.StringVar(&rsyncoptions.Hostname, "rsync-hostname", "", "Rsync host")
flag.StringVar(&rsyncoptions.Username, "rsync-username", "", "Rsync username")
flag.StringVar(&rsyncoptions.Destination, "rsync-destination", ".", "Rsync Destination directory")
flag.StringVar(&rsyncoptions.Rsh, "rsync-rsh", ".", "Rsync rsh command")
flag.IntVar(&poolTime, "pool-time", 30, "Number of second to check new files to sync")
flag.Parse()
@ -59,6 +60,7 @@ func main() {
Username: rsyncoptions.Username,
Hostname: rsyncoptions.Hostname,
Destination: rsyncoptions.Destination,
Rsh: rsyncoptions.Rsh,
Path: t.Path,
OnProgress: func(p int) {
err := qcli.SetProgress(t, p)

View File

@ -15,6 +15,7 @@ type RsyncOptions struct {
Hostname string
Path string
Destination string
Rsh string
OnProgress func(p int)
}
@ -29,6 +30,7 @@ func (r *RsyncOptions) Uri() string {
type Rsync struct {
Source string
Destination string
Rsh string
OnProgress func(p int)
progress int
@ -38,6 +40,7 @@ func NewRsync(options *RsyncOptions) *Rsync {
return &Rsync{
Source: options.Uri(),
Destination: options.Destination,
Rsh: options.Rsh,
OnProgress: options.OnProgress,
progress: -1,
}
@ -60,15 +63,20 @@ func ScanCR(data []byte, atEOF bool) (advance int, token []byte, err error) {
}
func (r *Rsync) Run() error {
cmd := exec.Command(
"rsync",
args := []string{
"--archive",
"--partial",
"--inplace",
"--no-inc-recursive",
"--info=progress2",
r.Source,
r.Destination,
}
if r.Rsh != "" {
args = append(args, "--rsh", r.Rsh)
}
args = append(args, r.Source, r.Destination)
cmd := exec.Command(
"rsync",
args...,
)
out, err := cmd.StdoutPipe()
if err != nil {