[ftputil] Problem using FTPHost.makedirs()

Roger Demetrescu roger.demetrescu at gmail.com
Tue Nov 4 18:04:49 CET 2014


Ok... I did some more testes and found out that I am not able to see
any files/directories inside:

/aaa
/aaa/bbb


I had to change FTPHost's makedirs implementation to this code:


    # Ignore unused argument `mode`
    # pylint: disable=unused-argument
    def makedirs(self, path, mode=None):
        """
        Make the directory `path`, but also make not yet existing
        intermediate directories, like `os.makedirs`. The value
        of `mode` is only accepted for compatibility with
        `os.makedirs` but otherwise ignored.
        """
        path = ftputil.tool.as_unicode(path)
        path = self.path.abspath(path)
        directories = path.split(self.sep)
        old_dir = self.getcwd()

        try:
            # Try to build the directory chain from the "uppermost" to
            # the "lowermost" directory.
            for index in range(1, len(directories)):
                # Re-insert the separator which got lost by using `path.split`.
                next_directory = self.sep +
self.path.join(*directories[:index+1])
                try:
                    self.chdir(next_directory)
                except ftputil.error.PermanentError:
                    self.mkdir(next_directory)
        finally:
            self.chdir(old_dir)



It works like a charm...   :)


[]s
Roger







On Mon, Nov 3, 2014 at 11:51 PM, Roger Demetrescu
<roger.demetrescu at gmail.com> wrote:
> Hi Stefan, how are you doing?
>
>
> I've find an issue with ftputil 3.2 (well, it happens with 2.8 and 3.0
> too) when trying to use host.makedirs() withing a FTP server that
> doesnt show any directories/files under de root ('/')
>
> My customer gave me this directory to work:
>
> /aaa/bbb/ccc
>
>
> When I try to create this directory:   ./ddd/eee/
> FTPHost.makedirs() try do create those directories:
>
> /aaa
> /aaa/bbb
> /aaa/bbb/ccc
> /aaa/bbb/ccc/ddd
> /aaa/bbb/ccc/ddd/eee
>
>
>
> Of course, /aaa already exists, and the ftputil does this check to see
> if it should reraise the exception:
>
>     if not self.path.isdir(next_directory):
>
>
>
> The problem is: I am able to do a host.chdir('/aaa/bbb/ccc')
> but if I do a host.chdir('/') and try to list de files and
> directories, it returns an empty list.
>
>
> Using FileZilla to connect to this FTP server gave me the same result.
> I am able to see all files and directories under /aaa/bbb/ccc but I
> see nothing under the root:  /
>
>
> FTP is a Microsoft FTP Service (don't know any more details).
>
>
> So, any suggestion on how to make ftputil stop trying to create theses
> directories:
>
> /aaa
> /aaa/bbb
> /aaa/bbb/ccc
>
>
> and only try to create:
>
> /aaa/bbb/ccc/ddd
> /aaa/bbb/ccc/ddd/eee
>
>
> since my current directory is already /aaa/bbb/ccc ?
>
>
> Thanks in advance!
>
>
> Roger


More information about the ftputil mailing list