2019-10-24 16:50:35 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/drakkan/sftpgo/dataprovider"
|
|
|
|
"github.com/drakkan/sftpgo/service"
|
2019-11-18 22:30:37 +00:00
|
|
|
"github.com/drakkan/sftpgo/sftpd"
|
2019-10-24 16:50:35 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-10-26 16:25:53 +00:00
|
|
|
directoryToServe string
|
|
|
|
portableSFTPDPort int
|
|
|
|
portableAdvertiseService bool
|
|
|
|
portableAdvertiseCredentials bool
|
|
|
|
portableUsername string
|
|
|
|
portablePassword string
|
|
|
|
portableLogFile string
|
|
|
|
portablePublicKeys []string
|
|
|
|
portablePermissions []string
|
2019-11-18 22:30:37 +00:00
|
|
|
portableSSHCommands []string
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd = &cobra.Command{
|
2019-10-24 16:50:35 +00:00
|
|
|
Use: "portable",
|
|
|
|
Short: "Serve a single directory",
|
|
|
|
Long: `To serve the current working directory with auto generated credentials simply use:
|
|
|
|
|
|
|
|
sftpgo portable
|
|
|
|
|
|
|
|
Please take a look at the usage below to customize the serving parameters`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
portableDir := directoryToServe
|
|
|
|
if !filepath.IsAbs(portableDir) {
|
|
|
|
portableDir, _ = filepath.Abs(portableDir)
|
|
|
|
}
|
|
|
|
service := service.Service{
|
|
|
|
ConfigDir: defaultConfigDir,
|
|
|
|
ConfigFile: defaultConfigName,
|
2019-10-26 16:25:53 +00:00
|
|
|
LogFilePath: portableLogFile,
|
2019-10-24 16:50:35 +00:00
|
|
|
LogMaxSize: defaultLogMaxSize,
|
|
|
|
LogMaxBackups: defaultLogMaxBackup,
|
|
|
|
LogMaxAge: defaultLogMaxAge,
|
|
|
|
LogCompress: defaultLogCompress,
|
|
|
|
LogVerbose: defaultLogVerbose,
|
|
|
|
Shutdown: make(chan bool),
|
|
|
|
PortableMode: 1,
|
|
|
|
PortableUser: dataprovider.User{
|
|
|
|
Username: portableUsername,
|
|
|
|
Password: portablePassword,
|
|
|
|
PublicKeys: portablePublicKeys,
|
|
|
|
Permissions: portablePermissions,
|
|
|
|
HomeDir: portableDir,
|
2019-11-13 10:36:21 +00:00
|
|
|
Status: 1,
|
2019-10-24 16:50:35 +00:00
|
|
|
},
|
|
|
|
}
|
2019-11-18 22:30:37 +00:00
|
|
|
if err := service.StartPortableMode(portableSFTPDPort, portableSSHCommands, portableAdvertiseService,
|
2019-10-26 16:25:53 +00:00
|
|
|
portableAdvertiseCredentials); err == nil {
|
2019-10-24 16:50:35 +00:00
|
|
|
service.Wait()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
portableCmd.Flags().StringVarP(&directoryToServe, "directory", "d", ".",
|
|
|
|
"Path to the directory to serve. This can be an absolute path or a path relative to the current directory")
|
|
|
|
portableCmd.Flags().IntVarP(&portableSFTPDPort, "sftpd-port", "s", 0, "0 means a random non privileged port")
|
2019-11-18 22:30:37 +00:00
|
|
|
portableCmd.Flags().StringSliceVarP(&portableSSHCommands, "ssh-commands", "c", sftpd.GetDefaultSSHCommands(),
|
|
|
|
"SSH commands to enable. \"*\" means any supported SSH command including scp")
|
2019-10-24 16:50:35 +00:00
|
|
|
portableCmd.Flags().StringVarP(&portableUsername, "username", "u", "", "Leave empty to use an auto generated value")
|
|
|
|
portableCmd.Flags().StringVarP(&portablePassword, "password", "p", "", "Leave empty to use an auto generated value")
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd.Flags().StringVarP(&portableLogFile, logFilePathFlag, "l", "", "Leave empty to disable logging")
|
2019-10-24 16:50:35 +00:00
|
|
|
portableCmd.Flags().StringSliceVarP(&portablePublicKeys, "public-key", "k", []string{}, "")
|
|
|
|
portableCmd.Flags().StringSliceVarP(&portablePermissions, "permissions", "g", []string{"list", "download"},
|
|
|
|
"User's permissions. \"*\" means any permission")
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd.Flags().BoolVarP(&portableAdvertiseService, "advertise-service", "S", true,
|
2019-11-08 07:43:27 +00:00
|
|
|
"Advertise SFTP service using multicast DNS")
|
2019-10-26 16:25:53 +00:00
|
|
|
portableCmd.Flags().BoolVarP(&portableAdvertiseCredentials, "advertise-credentials", "C", false,
|
2019-11-14 13:18:43 +00:00
|
|
|
"If the SFTP service is advertised via multicast DNS this flag allows to put username/password inside the advertised TXT record")
|
2019-10-24 16:50:35 +00:00
|
|
|
rootCmd.AddCommand(portableCmd)
|
|
|
|
}
|