Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

ftp: fix RangeOption support in Open #1825

Fabian Möller17dabf7a99ce
diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go
index eb7da5c1f..7f333550d 100644
--- a/backend/ftp/ftp.go
+++ b/backend/ftp/ftp.go
@@ -16,6 +16,7 @@ import (
"github.com/ncw/rclone/fs/config"
"github.com/ncw/rclone/fs/config/obscure"
"github.com/ncw/rclone/fs/hash"
+ "github.com/ncw/rclone/lib/readers"
"github.com/pkg/errors"
)
@@ -633,11 +634,13 @@ func (f *ftpReadCloser) Close() error {
func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error) {
// defer fs.Trace(o, "")("rc=%v, err=%v", &rc, &err)
path := path.Join(o.fs.root, o.remote)
- var offset int64
+ var offset, limit int64
for _, option := range options {
switch x := option.(type) {
case *fs.SeekOption:
- offset = x.Offset
+ offset, limit = x.Offset, 0
+ case *fs.RangeOption:
+ offset, limit = x.Decode(o.Size())
default:
if option.Mandatory() {
fs.Logf(o, "Unsupported mandatory option: %v", option)
@@ -653,7 +656,7 @@ func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error) {
o.fs.putFtpConnection(&c, err)
return nil, errors.Wrap(err, "open")
}
- rc = &ftpReadCloser{rc: fd, c: c, f: o.fs}
+ rc = &ftpReadCloser{rc: readers.NewLimitedReadCloser(fd, limit), c: c, f: o.fs}
return rc, nil
}