ftp

package
v4.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FTPSyncCmd = &cobra.Command{
	Use:          "sync <localdir> <ftpurl>",
	Short:        "sync ICE's FTP directory to a local path",
	SilenceUsage: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 2 || args[0] == "" || args[1] == "" {
			return cmd.Help()
		}

		dataDir := args[0]
		rawFtpURL := args[1]
		ftpURL, err := url.Parse(rawFtpURL)
		if err != nil {
			log.Error("Please provide a valid url!")
			return err
		}

		if err2 := os.MkdirAll(dataDir, 0o777); err2 != nil {
			log.Error("Cannot create local storage directory: %+v", err2)
			return err
		}

		password, ok := ftpURL.User.Password()
		if !ok {
			log.Error("Please provide a password in the FTP url!")
			return err
		}
		client, err := ftp.NewClient(ftpURL.User.Username(), password, ftpURL.Host)
		if err != nil {
			log.Error("Unable to connect to ICE: %+v", err)
			return err
		}
		defer func() { client.Close() }()

		log.Info("Successfully connected to ICE: %+v", ftpURL)

		reorgLoader := ftp.NewDownloader(client, ftpURL.Path, dataDir, enum.ReorgFilePrefix)
		newFiles, err := reorgLoader.Sync()
		if err != nil {
			log.Error("Error occurred while downloading files: %+v", err)
			return err
		}
		log.Info("New reorg files downloaded: %+v", newFiles)

		sirsLoader := ftp.NewDownloader(client, ftpURL.Path, dataDir, enum.SirsFilePrefix)
		newFiles, err = sirsLoader.Sync()
		if err != nil {
			log.Error("Error occurred while downloading files: %+v", err)
			return err
		}
		log.Info("New sirs files downloaded: %+v", newFiles)

		return nil
	},
}

FTPSyncCmd downloads reorg and sirs files from ICE's ftp directory to a local 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