Hi everybody!

I want to get list of files and folders with permission from ftp!

This is my code:

from ftplib import FTP
ftp=FTP('ftp.domain.com','username','pass')
a=ftp.dir('')

after runnig : (Output)

drwxrwxrwx 1 user group 0 Mar 01 14:29 Backup
drwxrwxrwx 1 user group 0 Mar 01 14:29 logs
drwxrwxrwx 1 user group 0 Apr 17 18:01 www

but when I run it , the "a" variable is empty! and I cannot use it.
I want to get files and folders with permissions from ftp and write these in file(a.txt)!

please help me.

Recommended Answers

All 3 Replies

This is a documented behaviour. FTP.dir() returns None. However, it calls a callback function for each line of the transfer. The default callback prints lines to stdout. You need to provide your own callback.

Thanks.

Can you give me simple code?

There's an example at the top of paragraph 20.11 (ftplib) of python documentation. See how a callback is passed to retrbinary. You need a similar setup for your ftp.dir() - or better ftp.retrlines('LIST', callback).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.