Question

In my script I want to be able, in the end, to be able to download all files in a directory and all sub-directories... So I am trying FTPLIB. I'm trying to call dir of my ftp server and put it into a variable, but I get NONETYPE?! I can connect to the server and when I call directory = session.dir() It displays a kind of matrix style output in the console with files, read/write perms, dates, etc.... But when I then try to print Directory all I seem to get is "None". My initial idea was to for each item in the directory download them to my computer, but I can't seem to get a list of the directory!

directory = session.dir()
print(str(directory))

Sorry for the long and probably trivial explanation, but I have become a little bit too frustrated.

Any help would be very much appreciated!

-Clem

Était-ce utile?

La solution

First, read this. http://docs.python.org/library/ftplib.html#ftplib.FTP.nlst

Then, try this:

directory = session.nlst()
print(directory)

Note. You don't need to do print(str(...)). The print function gets the string representation for you.

Autres conseils

In the official docs, the very first example shows how to do what you need: use .retrlines('LIST') to read the output of LIST command.

Another way is to use .nlst().

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top