Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTPFS, why don't use the rename directive (RNRF RNTO) to implement the move method #581

Open
CDU-Ge opened this issue Dec 3, 2023 · 1 comment

Comments

@CDU-Ge
Copy link

CDU-Ge commented Dec 3, 2023

I've noticed that in FTPFS, the implementation of move comes from FS, however, when moving in FTPFS, it's too slow, especially when renaming.

@CDU-Ge
Copy link
Author

CDU-Ge commented Dec 3, 2023

for example:

import fs
from fs.ftpfs import FTPFS as _FTPFS
from fs.ftpfs import ftp_errors


class NotSupportedError(Exception):
    pass


class FTPFS(_FTPFS):
    def move(self, src_path: str, dst_path: str, overwrite=False, preserve_time=False):
        try:
            with self._lock:
                _path = self.validatepath(dst_path)
                if not overwrite and self.exists(_path):
                    raise fs.errors.DestinationExists(_path)
                with ftp_errors(self, _path):
                    try:
                        if overwrite:
                            with ftp_errors(self, _path):
                                if self.exists(_path):
                                    self.ftp.rename(_path, _path + ".pyfilesystem2.tmp")
                                    self.ftp.rename(src_path, dst_path)
                                    self.ftp.delete(_path + ".pyfilesystem2.tmp")
                        else:
                            self.ftp.rename(src_path, dst_path)
                    except ftplib.error_perm as e:
                        if str(e) == "550 RNTO failed.":  # some ftp server does not support rename to other directory
                            raise NotSupportedError()
                        raise e
        except NotSupportedError:
            super().move(src_path, dst_path, overwrite, preserve_time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant