github.com/scaleway/scaleway-cli@v1.11.1/pkg/cli/cmd_cp.go (about) 1 // Copyright (C) 2015 Scaleway. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE.md file. 4 5 package cli 6 7 import "github.com/scaleway/scaleway-cli/pkg/commands" 8 9 var cmdCp = &Command{ 10 Exec: runCp, 11 UsageLine: "cp [OPTIONS] SERVER:PATH|HOSTPATH|- SERVER:PATH|HOSTPATH|-", 12 Description: "Copy files/folders from a PATH on the server to a HOSTDIR on the host", 13 Help: "Copy files/folders from a PATH on the server to a HOSTDIR on the host\nrunning the command. Use '-' to write the data as a tar file to STDOUT.", 14 Examples: ` 15 $ scw cp path/to/my/local/file myserver:path 16 $ scw cp --gateway=myotherserver path/to/my/local/file myserver:path 17 $ scw cp myserver:path/to/file path/to/my/local/dir 18 $ scw cp myserver:path/to/file myserver2:path/to/dir 19 $ scw cp myserver:path/to/file - > myserver-pathtofile-backup.tar 20 $ scw cp myserver:path/to/file - | tar -tvf - 21 $ scw cp path/to/my/local/dir myserver:path 22 $ scw cp myserver:path/to/dir path/to/my/local/dir 23 $ scw cp myserver:path/to/dir myserver2:path/to/dir 24 $ scw cp myserver:path/to/dir - > myserver-pathtodir-backup.tar 25 $ scw cp myserver:path/to/dir - | tar -tvf - 26 $ cat archive.tar | scw cp - myserver:/path 27 $ tar -cvf - . | scw cp - myserver:path 28 `, 29 } 30 31 func init() { 32 cmdCp.Flag.BoolVar(&cpHelp, []string{"h", "-help"}, false, "Print usage") 33 cmdCp.Flag.StringVar(&cpGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway") 34 cmdCp.Flag.StringVar(&cpSSHUser, []string{"-user"}, "root", "Specify SSH user") 35 cmdCp.Flag.IntVar(&cpSSHPort, []string{"-p", "-port"}, 22, "Specify SSH port") 36 } 37 38 // Flags 39 var cpHelp bool // -h, --help flag 40 var cpGateway string // -g, --gateway flag 41 var cpSSHUser string // --user flag 42 var cpSSHPort int // -p, --port flag 43 44 func runCp(cmd *Command, rawArgs []string) error { 45 if cpHelp { 46 return cmd.PrintUsage() 47 } 48 if len(rawArgs) != 2 { 49 return cmd.PrintShortUsage() 50 } 51 52 args := commands.CpArgs{ 53 Gateway: cpGateway, 54 Source: rawArgs[0], 55 Destination: rawArgs[1], 56 SSHUser: cpSSHUser, 57 SSHPort: cpSSHPort, 58 } 59 ctx := cmd.GetContext(rawArgs) 60 return commands.RunCp(ctx, args) 61 }