문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top