Skip to content

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

Open

Description

@CDU-Ge

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.

Activity

  1. CDU-Ge commented on Dec 3, 2023

    @CDU-Ge
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions