0

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.

Edited by morteza_ipo: n/a

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by nezachem
0

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.

0

Thanks.

Can you give me simple code?

Edited by morteza_ipo: n/a

1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.