github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/cmd/rcat/rcat.go (about)

     1  package rcat
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/ncw/rclone/cmd"
    10  	"github.com/ncw/rclone/fs/operations"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  func init() {
    15  	cmd.Root.AddCommand(commandDefintion)
    16  }
    17  
    18  var commandDefintion = &cobra.Command{
    19  	Use:   "rcat remote:path",
    20  	Short: `Copies standard input to file on remote.`,
    21  	Long: `
    22  rclone rcat reads from standard input (stdin) and copies it to a
    23  single remote file.
    24  
    25      echo "hello world" | rclone rcat remote:path/to/file
    26      ffmpeg - | rclone rcat remote:path/to/file
    27  
    28  If the remote file already exists, it will be overwritten.
    29  
    30  rcat will try to upload small files in a single request, which is
    31  usually more efficient than the streaming/chunked upload endpoints,
    32  which use multiple requests. Exact behaviour depends on the remote.
    33  What is considered a small file may be set through
    34  ` + "`--streaming-upload-cutoff`" + `. Uploading only starts after
    35  the cutoff is reached or if the file ends before that. The data
    36  must fit into RAM. The cutoff needs to be small enough to adhere
    37  the limits of your remote, please see there. Generally speaking,
    38  setting this cutoff too high will decrease your performance.
    39  
    40  Note that the upload can also not be retried because the data is
    41  not kept around until the upload succeeds. If you need to transfer
    42  a lot of data, you're better off caching locally and then
    43  ` + "`rclone move`" + ` it to the destination.`,
    44  	Run: func(command *cobra.Command, args []string) {
    45  		cmd.CheckArgs(1, 1, command, args)
    46  
    47  		stat, _ := os.Stdin.Stat()
    48  		if (stat.Mode() & os.ModeCharDevice) != 0 {
    49  			log.Fatalf("nothing to read from standard input (stdin).")
    50  		}
    51  
    52  		fdst, dstFileName := cmd.NewFsDstFile(args)
    53  		cmd.Run(false, false, command, func() error {
    54  			_, err := operations.Rcat(context.Background(), fdst, dstFileName, os.Stdin, time.Now())
    55  			return err
    56  		})
    57  	},
    58  }