github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/cmd/copyto/copyto.go (about)

     1  package copyto
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/rclone/rclone/cmd"
     7  	"github.com/rclone/rclone/fs/operations"
     8  	"github.com/rclone/rclone/fs/sync"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  func init() {
    13  	cmd.Root.AddCommand(commandDefinition)
    14  }
    15  
    16  var commandDefinition = &cobra.Command{
    17  	Use:   "copyto source:path dest:path",
    18  	Short: `Copy files from source to dest, skipping already copied`,
    19  	Long: `
    20  If source:path is a file or directory then it copies it to a file or
    21  directory named dest:path.
    22  
    23  This can be used to upload single files to other than their current
    24  name.  If the source is a directory then it acts exactly like the copy
    25  command.
    26  
    27  So
    28  
    29      rclone copyto src dst
    30  
    31  where src and dst are rclone paths, either remote:path or
    32  /path/to/local or C:\windows\path\if\on\windows.
    33  
    34  This will:
    35  
    36      if src is file
    37          copy it to dst, overwriting an existing file if it exists
    38      if src is directory
    39          copy it to dst, overwriting existing files if they exist
    40          see copy command for full details
    41  
    42  This doesn't transfer unchanged files, testing by size and
    43  modification time or MD5SUM.  It doesn't delete files from the
    44  destination.
    45  
    46  **Note**: Use the ` + "`-P`" + `/` + "`--progress`" + ` flag to view real-time transfer statistics
    47  `,
    48  	Run: func(command *cobra.Command, args []string) {
    49  		cmd.CheckArgs(2, 2, command, args)
    50  		fsrc, srcFileName, fdst, dstFileName := cmd.NewFsSrcDstFiles(args)
    51  		cmd.Run(true, true, command, func() error {
    52  			if srcFileName == "" {
    53  				return sync.CopyDir(context.Background(), fdst, fsrc, false)
    54  			}
    55  			return operations.CopyFile(context.Background(), fdst, fsrc, dstFileName, srcFileName)
    56  		})
    57  	},
    58  }