2017-08-03 21:42:35 +02:00
|
|
|
package rcat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ncw/rclone/cmd"
|
2018-01-12 17:30:54 +01:00
|
|
|
"github.com/ncw/rclone/fs/operations"
|
2017-08-03 21:42:35 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmd.Root.AddCommand(commandDefintion)
|
|
|
|
}
|
|
|
|
|
|
|
|
var commandDefintion = &cobra.Command{
|
|
|
|
Use: "rcat remote:path",
|
|
|
|
Short: `Copies standard input to file on remote.`,
|
|
|
|
Long: `
|
|
|
|
rclone rcat reads from standard input (stdin) and copies it to a
|
|
|
|
single remote file.
|
|
|
|
|
|
|
|
echo "hello world" | rclone rcat remote:path/to/file
|
2018-06-14 12:29:53 +02:00
|
|
|
ffmpeg - | rclone rcat remote:path/to/file
|
2017-09-11 08:26:53 +02:00
|
|
|
|
|
|
|
If the remote file already exists, it will be overwritten.
|
|
|
|
|
|
|
|
rcat will try to upload small files in a single request, which is
|
|
|
|
usually more efficient than the streaming/chunked upload endpoints,
|
|
|
|
which use multiple requests. Exact behaviour depends on the remote.
|
|
|
|
What is considered a small file may be set through
|
|
|
|
` + "`--streaming-upload-cutoff`" + `. Uploading only starts after
|
|
|
|
the cutoff is reached or if the file ends before that. The data
|
|
|
|
must fit into RAM. The cutoff needs to be small enough to adhere
|
|
|
|
the limits of your remote, please see there. Generally speaking,
|
|
|
|
setting this cutoff too high will decrease your performance.
|
|
|
|
|
|
|
|
Note that the upload can also not be retried because the data is
|
|
|
|
not kept around until the upload succeeds. If you need to transfer
|
|
|
|
a lot of data, you're better off caching locally and then
|
|
|
|
` + "`rclone move`" + ` it to the destination.`,
|
2017-08-03 21:42:35 +02:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
|
|
|
|
|
|
stat, _ := os.Stdin.Stat()
|
|
|
|
if (stat.Mode() & os.ModeCharDevice) != 0 {
|
|
|
|
log.Fatalf("nothing to read from standard input (stdin).")
|
|
|
|
}
|
|
|
|
|
|
|
|
fdst, dstFileName := cmd.NewFsDstFile(args)
|
|
|
|
cmd.Run(false, false, command, func() error {
|
2018-01-12 17:30:54 +01:00
|
|
|
_, err := operations.Rcat(fdst, dstFileName, os.Stdin, time.Now())
|
2017-09-16 22:49:08 +02:00
|
|
|
return err
|
2017-08-03 21:42:35 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|