2022-08-28 13:21:57 +02:00
|
|
|
// Package rcat provides the rcat command.
|
2017-08-03 21:42:35 +02:00
|
|
|
package rcat
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2017-08-03 21:42:35 +02:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2024-08-18 16:58:35 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
2021-04-13 13:25:47 +02:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2017-08-03 21:42:35 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-04-13 13:25:47 +02:00
|
|
|
var (
|
|
|
|
size = int64(-1)
|
|
|
|
)
|
|
|
|
|
2017-08-03 21:42:35 +02:00
|
|
|
func init() {
|
2019-10-11 17:58:11 +02:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2021-04-13 13:25:47 +02:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
2023-07-10 19:34:10 +02:00
|
|
|
flags.Int64VarP(cmdFlags, &size, "size", "", size, "File size hint to preallocate", "")
|
2017-08-03 21:42:35 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 17:58:11 +02:00
|
|
|
var commandDefinition = &cobra.Command{
|
2017-08-03 21:42:35 +02:00
|
|
|
Use: "rcat remote:path",
|
|
|
|
Short: `Copies standard input to file on remote.`,
|
2024-08-12 18:17:46 +02:00
|
|
|
Long: `Reads from standard input (stdin) and copies it to a single remote file.
|
2017-08-03 21:42:35 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2022-06-19 19:55:37 +02:00
|
|
|
Use the ` + "`--size`" + ` flag to preallocate the file in advance at the remote end
|
2021-04-13 13:25:47 +02:00
|
|
|
and actually stream it, even if remote backend doesn't support streaming.
|
|
|
|
|
2022-06-19 19:55:37 +02:00
|
|
|
` + "`--size`" + ` should be the exact size of the input stream in bytes. If the
|
|
|
|
size of the stream is different in length to the ` + "`--size`" + ` passed in
|
2021-04-13 13:25:47 +02:00
|
|
|
then the transfer will likely fail.
|
|
|
|
|
2023-03-17 11:51:19 +01:00
|
|
|
Note that the upload cannot be retried because the data is not stored.
|
|
|
|
If the backend supports multipart uploading then individual chunks can
|
|
|
|
be retried. If you need to transfer a lot of data, you may be better
|
|
|
|
off caching it locally and then ` + "`rclone move`" + ` it to the
|
|
|
|
destination which can use retries.`,
|
2022-11-26 23:40:49 +01:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.38",
|
2023-07-10 19:34:10 +02:00
|
|
|
"groups": "Important",
|
2022-11-26 23:40:49 +01:00
|
|
|
},
|
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 {
|
2024-08-18 16:58:35 +02:00
|
|
|
fs.Fatalf(nil, "nothing to read from standard input (stdin).")
|
2017-08-03 21:42:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fdst, dstFileName := cmd.NewFsDstFile(args)
|
|
|
|
cmd.Run(false, false, command, func() error {
|
2022-11-08 18:42:18 +01:00
|
|
|
_, err := operations.RcatSize(context.Background(), fdst, dstFileName, os.Stdin, size, time.Now(), nil)
|
2017-09-16 22:49:08 +02:00
|
|
|
return err
|
2017-08-03 21:42:35 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|