diff --git a/server/ftp/afero.go b/server/ftp/afero.go index 866ad8c0..448744b1 100644 --- a/server/ftp/afero.go +++ b/server/ftp/afero.go @@ -6,6 +6,7 @@ import ( ftpserver "github.com/KirCute/ftpserverlib-pasvportmap" "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/fs" + "github.com/alist-org/alist/v3/internal/model" "github.com/spf13/afero" "os" "time" @@ -91,7 +92,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve if (flags & os.O_APPEND) != 0 { return nil, errs.NotSupport } - _, err := fs.Get(a.ctx, name, &fs.GetArgs{}) + user := a.ctx.Value("user").(*model.User) + path, err := user.JoinPath(name) + if err != nil { + return nil, err + } + _, err = fs.Get(a.ctx, path, &fs.GetArgs{}) exists := err == nil if (flags&os.O_CREATE) == 0 && !exists { return nil, errs.ObjectNotFound @@ -102,12 +108,12 @@ func (a *AferoAdapter) GetHandle(name string, flags int, offset int64) (ftpserve if (flags & os.O_WRONLY) != 0 { trunc := (flags & os.O_TRUNC) != 0 if fileSize > 0 { - return OpenUploadWithLength(a.ctx, name, trunc, fileSize) + return OpenUploadWithLength(a.ctx, path, trunc, fileSize) } else { - return OpenUpload(a.ctx, name, trunc) + return OpenUpload(a.ctx, path, trunc) } } - return OpenDownload(a.ctx, name) + return OpenDownload(a.ctx, path) } func (a *AferoAdapter) SetNextFileSize(size int64) { diff --git a/server/ftp/fsread.go b/server/ftp/fsread.go index 6a9ba2eb..91f87bf4 100644 --- a/server/ftp/fsread.go +++ b/server/ftp/fsread.go @@ -25,12 +25,8 @@ type FileDownloadProxy struct { closers *utils.Closers } -func OpenDownload(ctx context.Context, path string) (*FileDownloadProxy, error) { +func OpenDownload(ctx context.Context, reqPath string) (*FileDownloadProxy, error) { user := ctx.Value("user").(*model.User) - reqPath, err := user.JoinPath(path) - if err != nil { - return nil, err - } meta, err := op.GetNearestMeta(reqPath) if err != nil { if !errors.Is(errors.Cause(err), errs.MetaNotFound) { diff --git a/server/ftp/fsup.go b/server/ftp/fsup.go index f18c13c2..96c84681 100644 --- a/server/ftp/fsup.go +++ b/server/ftp/fsup.go @@ -29,10 +29,6 @@ type FileUploadProxy struct { func uploadAuth(ctx context.Context, path string) error { user := ctx.Value("user").(*model.User) - path, err := user.JoinPath(path) - if err != nil { - return err - } meta, err := op.GetNearestMeta(stdpath.Dir(path)) if err != nil { if !errors.Is(errors.Cause(err), errs.MetaNotFound) {