[Tutor] ftp recursive directory function doesn't work.

David bouncingcats at gmail.com
Wed Dec 14 04:47:33 EST 2022


On Wed, 14 Dec 2022 at 19:48, <mhysnm1964 at gmail.com> wrote:

> I am trying to navigate a ftp server directory structure to see how big the
> directory actually is. The function recursively goes through the
> directories. When I pass the first if test calling the os object. I get a
> file not found error and it breaks. Everything in the first level directory
> are directories. I cannot work out what is going wrong.

>     files = ftp.nlst(b <ftp://ftp.nlst(b>  )

Hi, this gives you a list of files that are on the *server*.

>     for file in files:
>         if os.path.isdir(file):

And there you check to see if that file is a directory on the *client*.

You need to replace your os.path.isdir() test
with a different approach that can test for directories
using information available from the server.

At a casual glance, perhaps you could parse the
output of
  ftp.retrlines('LIST')
or there might be a better way.


More information about the Tutor mailing list