ftp

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DownloadCmd = &cobra.Command{
	Use:     "download [SERVER NAME]:[FILE PATH]",
	Aliases: []string{"cp"},
	Short:   "Transfer a file from a remote server",
	Example: `
	alpacon download myserver:/home/alpacon/alpacon.txt
	alpacon cp myserver:/home/alpacon/alpacon.txt
	`,
	Args: cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		upload := strings.SplitN(args[0], ":", 2)

		if len(upload) != 2 {
			utils.CliError("invalid argument format for [SERVER NAME]:[FILE PATH]. Please provide the server name and path separated by a colon")
		}

		serverName := upload[0]
		path := upload[1]

		alpaconClient, err := client.NewAlpaconAPIClient()
		if err != nil {
			utils.CliError("Connection to Alpacon API failed: %s. Consider re-logging.", err)
		}

		downloadURL, err := ftp.DownloadFile(alpaconClient, serverName, path)
		if err != nil {
			utils.CliError("Failed to download the file from server: %s", err)
		}

		utils.CliInfo("`%s` successfully downloaded from server `%s`. Download URL: %s", path, serverName, downloadURL)
	},
}
View Source
var UploadCmd = &cobra.Command{
	Use:     "upload [FILE PATH] [SERVER NAME]:[UPLOAD PATH]",
	Aliases: []string{"cp"},
	Short:   "Transfer a file to a remote server",
	Example: `
	alpacon upload alpacon.txt myserver:/home/alpacon/
	alpacon cp /Users/alpacon.txt myserver:/home/alpacon/
	`,
	Args: cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		file := args[0]
		upload := strings.SplitN(args[1], ":", 2)

		if len(upload) != 2 {
			utils.CliError("invalid argument format for [SERVER NAME]:[UPLOAD PATH]. Please provide the server name and path separated by a colon")
		}

		serverName := upload[0]
		path := upload[1]

		alpaconClient, err := client.NewAlpaconAPIClient()
		if err != nil {
			utils.CliError("Connection to Alpacon API failed: %s. Consider re-logging.", err)
		}

		err = ftp.UploadFile(alpaconClient, file, serverName, path)
		if err != nil {
			utils.CliError("Failed to upload the file to server %s", err)
		}

		utils.CliInfo("`%s` successfully uploaded to server `%s` at `%s` ", file, serverName, path)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL