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

compatibility with weird windows ftp client #559

Open
jk987 opened this issue Nov 1, 2021 · 0 comments
Open

compatibility with weird windows ftp client #559

jk987 opened this issue Nov 1, 2021 · 0 comments

Comments

@jk987
Copy link

jk987 commented Nov 1, 2021

Customer's machine has some windows inside and also some ftp client.
This client periodically connects to my ftp server (based on pyftpdlib) to read requests and to store results.
The trouble is that the client runs on Windows while the server runs on Linux.
When the client sends ftp command

LIST requests_dir\*.*

then the server doesn't understand it.
(When I used FileZilla server on Windows then it was ok.)
I made following modifications to make it working.

handlers.py: FTPHandler.ftp_LIST():
(When there is * in path then I use glob library to get a list.)

            ...
            if isdir or "*" in path:
                if "*" in path:
                    basedir, filename = os.path.split(path)
                    import glob
                    listing = glob.glob(path)
                    for i in range(len(listing)):
                        basedir, listing[i] = os.path.split(listing[i])
                else:
                    listing = self.run_as_current_user(self.fs.listdir, path)
                    basedir = path
                #print "basedir", basedir, "listing", listing
                if isinstance(listing, list):
                    try:
                        # RFC 959 recommends the listing to be sorted.
                        listing.sort()
                    except UnicodeDecodeError:
                        # (Python 2 only) might happen on filesystem not
                        # supporting UTF8 meaning os.listdir() returned a list
                        # of mixed bytes and unicode strings:
                        # http://goo.gl/6DLHD
                        # http://bugs.python.org/issue683592
                        pass
                iterator = self.fs.format_list(basedir, listing)
            else:
                basedir, filename = os.path.split(path)
                #print "basedir", basedir, "filename", filename
                self.fs.lstat(path)  # raise exc in case of problems
                iterator = self.fs.format_list(basedir, [filename])
            ...

filesystems.py: AbstractedFS.ftpnorm():
(Always replace backslash. Not very smart, should be by some parameter.)

        ...
        # normalize string in a standard web-path notation having '/'
        # as separator.
        if True or os.sep == "\\":
            p = p.replace("\\", "/")
        ...

It is up to you whether you would get inspired by these modifications.
But they are necessary for me.

(edited formatting)

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