Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/alpamon/command/ftp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"github.com/alpacanetworks/alpamon-go/pkg/config"
"github.com/alpacanetworks/alpamon-go/pkg/logger"
"github.com/alpacanetworks/alpamon-go/pkg/runner"
"github.com/spf13/cobra"
Expand All @@ -10,13 +9,13 @@ import (
var ftpCmd = &cobra.Command{
Use: "ftp <url> <homeDirectory>",
Short: "Start worker for Web FTP",
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
data := runner.FtpConfigData{
URL: args[0],
HomeDirectory: args[1],
ServerURL: args[1],
HomeDirectory: args[2],
Logger: logger.NewFtpLogger(),
Settings: config.LoadConfig(),
}

RunFtpWorker(data)
Expand Down
11 changes: 7 additions & 4 deletions pkg/runner/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func (cr *CommandRunner) openFtp(data openFtpData) error {
executable,
"ftp",
data.URL,
config.GlobalSettings.ServerURL,
data.HomeDirectory,
)
cmd.SysProcAttr = sysProcAttr
Expand Down Expand Up @@ -727,9 +728,11 @@ func makeArchive(paths []string, bulk, recursive bool, sysProcAttr *syscall.SysP
}
}

err := cmd.Run()
if err != nil {
return "", err
if bulk || recursive {
err := cmd.Run()
if err != nil {
return "", err
}
}

return archiveName, nil
Expand All @@ -744,7 +747,7 @@ func fileDownload(data CommandData, sysProcAttr *syscall.SysProcAttr) (exitCode

isZip := isZipFile(content)
if isZip {
command := fmt.Sprintf("tee -a %s > /dev/null | unzip -n %s -d %s; rm %s",
command := fmt.Sprintf("tee -a %s > /dev/null && unzip -n %s -d %s; rm %s",
strings.ReplaceAll(data.Path, " ", "\\ "),
strings.ReplaceAll(data.Path, " ", "\\ "),
strings.ReplaceAll(filepath.Dir(data.Path), " ", "\\ "),
Expand Down
8 changes: 2 additions & 6 deletions pkg/runner/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"strings"

"github.com/alpacanetworks/alpamon-go/pkg/config"
"github.com/alpacanetworks/alpamon-go/pkg/logger"
"github.com/gorilla/websocket"
)
Expand All @@ -22,22 +21,19 @@ type FtpClient struct {
homeDirectory string
workingDirectory string
log logger.FtpLogger
settings config.Settings
}

func NewFtpClient(data FtpConfigData) *FtpClient {
headers := http.Header{
"Authorization": {fmt.Sprintf(`id="%s", key="%s"`, data.Settings.ID, data.Settings.Key)},
"Origin": {data.Settings.ServerURL},
"Origin": {data.ServerURL},
}

return &FtpClient{
requestHeader: headers,
url: strings.Replace(data.Settings.ServerURL, "http", "ws", 1) + data.URL,
url: strings.Replace(data.ServerURL, "http", "ws", 1) + data.URL,
homeDirectory: data.HomeDirectory,
workingDirectory: data.HomeDirectory,
log: data.Logger,
settings: data.Settings,
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/runner/ftp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"
"time"

"github.com/alpacanetworks/alpamon-go/pkg/config"
"github.com/alpacanetworks/alpamon-go/pkg/logger"
)

Expand All @@ -31,9 +30,9 @@ const (

type FtpConfigData struct {
URL string
ServerURL string
HomeDirectory string
Logger logger.FtpLogger
Settings config.Settings
}

type FtpData struct {
Expand Down